title: How to code for the list view in android studio instead of text view
body: <p>I am trying to develop an android app. In my app I am using text view for displaying the available BLE devices. But instead of text view I want to use list view. What changes are needed in my code? I am confusing about how to use list view and various adapters!
  Here I provide my code.</p>
  <h3>MainActivity</h3>
  <pre><code>public class MainActivity extends AppCompatActivity {
       BluetoothManager btManager;
       BluetoothAdapter btAdapter;
       BluetoothLeScanner btScanner;
       Button startScanningButton;
       Button stopScanningButton;
       TextView peripheralTextView;
       private final static int REQUEST_ENABLE_BT = 1;
       private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
   
       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
           peripheralTextView = (TextView) findViewById  (R.id.PeripheralTextView);
           peripheralTextView.setMovementMethod(new ScrollingMovementMethod());
           startScanningButton = (Button) findViewById(R.id.StartScanButton);
            startScanningButton.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   startScanning();
               }
           });
   
           stopScanningButton = (Button) findViewById(R.id.StopScanButton);
           stopScanningButton.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   stopScanning();
               }
           });
           stopScanningButton.setVisibility(View.INVISIBLE);
   
           btManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
           btAdapter = btManager.getAdapter();
           btScanner = btAdapter.getBluetoothLeScanner();
   
   
           if (btAdapter != null &amp;&amp; !btAdapter.isEnabled()) {
               Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
               startActivityForResult(enableIntent,REQUEST_ENABLE_BT);
           }
   
           
       }
   
       // Device scan callback.
       private ScanCallback leScanCallback = new ScanCallback() {
           @Override
           public void onScanResult(int callbackType, ScanResult result) {
               peripheralTextView.append(&quot;Device Name: &quot; + result.getDevice().getName() + &quot; rssi: &quot; + result.getRssi() + &quot;\n&quot;);
   // auto scroll for text view
    final int scrollAmount = peripheralTextView.getLayout  ().getLineTop (peripheralTextView.getLineCount())- peripheralTextView.getHeight();
               // if there is no need to scroll, scrollAmount will be &lt;=0
               if (scrollAmount &gt; 0)
                   peripheralTextView.scrollTo(0, scrollAmount);
           }
       };
   
   
       public void startScanning() {
           System.out.println(&quot;start scanning&quot;);
           peripheralTextView.setText(&quot;&quot;);
           startScanningButton.setVisibility(View.INVISIBLE);
           stopScanningButton.setVisibility(View.VISIBLE);
           AsyncTask.execute(new Runnable() {
               @Override
               public void run() {
                   btScanner.startScan(leScanCallback);
               }
           });
       }
   
       public void stopScanning() {
           System.out.println(&quot;stopping scanning&quot;);
           peripheralTextView.append(&quot;Stopped Scanning&quot;);
           startScanningButton.setVisibility(View.VISIBLE);
           stopScanningButton.setVisibility(View.INVISIBLE);
           AsyncTask.execute(new Runnable() {
               @Override
               public void run() {
                   btScanner.stopScan(leScanCallback);
               }
           });
       }
   }
   
  </code></pre>
  <h3>activity_main.xml</h3>
  <pre class="lang-xml prettyprint-override"><code> &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
       xmlns:tools=&quot;http://schemas.android.com/tools&quot;
       android:layout_width=&quot;match_parent&quot;
       android:layout_height=&quot;match_parent&quot;
       android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
       android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
       android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
       android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
       tools:context=&quot;com.example.nc.android.MainActivity&quot;&gt;
   
       &lt;TextView
           android:layout_width=&quot;wrap_content&quot;
           android:layout_height=&quot;wrap_content&quot;
           android:text=&quot;Hello Bluetooth Scanners!&quot; /&gt;
   
       &lt;Button
           android:layout_width=&quot;100dp&quot;
           android:layout_height=&quot;50dp&quot;
           android:text=&quot;Scan&quot;
           android:id=&quot;@+id/StartScanButton&quot;
           android:layout_marginTop=&quot;40dp&quot;/&gt;
   
       &lt;Button
           android:layout_width=&quot;wrap_content&quot;
           android:layout_height=&quot;50dp&quot;
           android:text=&quot;Stop Scanning&quot;
           android:id=&quot;@+id/StopScanButton&quot;
           android:layout_marginTop=&quot;40dp&quot;/&gt;
   
       &lt;TextView
           android:layout_width=&quot;match_parent&quot;
           android:layout_height=&quot;match_parent&quot;
           android:layout_marginTop=&quot;100dp&quot;
           android:id=&quot;@+id/PeripheralTextView&quot;
           android:scrollbars=&quot;vertical&quot;
           android:maxLines=&quot;30&quot; /&gt;
   
   &lt;/RelativeLayout&gt;
   
  </code></pre>