title: How can I create custom audio Listview from storage in Android?
body: <p>I'd create a custom audio Listview to display all audio files in storage.</p>
  <pre><code>
  public class AudioToSendActivity extends AppCompatActivity {
  
  
      private ArrayList&lt;String&gt; arrayList;
      private ListView listView;
      private ArrayAdapter&lt;String&gt; adapter;
      private static final int PERMISSION_REQUEST = 1;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_audio_send);
          listView = findViewById(R.id.list_view_audio);
  
          if(ContextCompat.checkSelfPermission(AudioToSendActivity.this,
                  Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
              if(ActivityCompat.shouldShowRequestPermissionRationale(AudioToSendActivity.this,
                      Manifest.permission.READ_EXTERNAL_STORAGE)) {
                  ActivityCompat.requestPermissions(AudioToSendActivity.this,
                          new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
              }
              else {
                  ActivityCompat.requestPermissions(AudioToSendActivity.this,
                          new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
              }
          }
          else {
              upload();
          }
  
      }
  
      private void upload() {
  
          listView = findViewById(R.id.list_view_audio);
          arrayList = new ArrayList&lt;&gt;();
          getAudio();
          adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, arrayList);
          listView.setAdapter(adapter);
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  // open music player to play desired song
              }
          });
  
      }
  
      public void getAudio() {
          ContentResolver contentResolver = getContentResolver();
          Uri audioUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
          SimpleDateFormat formatter = new SimpleDateFormat(&quot;dd/MM/yyyy hh:mm:ss&quot;);
          Cursor audioCursor = contentResolver.query(audioUri, null, null, null, null);
  
          if(audioCursor != null &amp;&amp; audioCursor.moveToFirst()) {
              int audioTitle = audioCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
              int audioDate = audioCursor.getColumnIndex(MediaStore.Audio.Media.DATE_ADDED);
  
              do {
                  String currentTitle = audioCursor.getString(audioTitle);
                  String currentDate = audioCursor.getString(audioDate);
  
                  if(currentDate != null) {
                      currentDate = formatter.format(audioDate);
                  }
                  arrayList.add(currentTitle + &quot;\n&quot; + currentDate);
              }
              while (audioCursor.moveToNext());
          }
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          switch(requestCode) {
              case PERMISSION_REQUEST: {
                  if(grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                      if(ContextCompat.checkSelfPermission(AudioToSendActivity.this,
                              Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                          Toast.makeText(this, &quot;Permission Granted&quot;, Toast.LENGTH_SHORT).show();
  
                          upload();
                      }
                  }
                  else {
                      Toast.makeText(this, &quot;Permission Denied&quot;, Toast.LENGTH_SHORT).show();
                      finish();
                  }
                  return;
              }
          }
      }
  }
  
  </code></pre>
  <p>This is my single_list_item.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/list_image_view&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;16dp&quot;
          android:layout_marginTop=&quot;16dp&quot;
          android:layout_marginBottom=&quot;16dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:srcCompat=&quot;@drawable/list_play_btn&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/list_title&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;16dp&quot;
          android:fontFamily=&quot;@font/open_sans_semibold&quot;
          android:text=&quot;Filename&quot;
          android:textColor=&quot;@color/colorDarkBlue&quot;
          android:textSize=&quot;16sp&quot;
          app:layout_constraintStart_toEndOf=&quot;@+id/list_image_view&quot;
          app:layout_constraintTop_toTopOf=&quot;@+id/list_image_view&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/list_date&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;16dp&quot;
          android:fontFamily=&quot;@font/open_sans&quot;
          android:text=&quot;TextView&quot;
          app:layout_constraintBottom_toBottomOf=&quot;@+id/list_image_view&quot;
          app:layout_constraintStart_toEndOf=&quot;@+id/list_image_view&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>This is my Audio class but I don't know how to custom Listview. I've create layout for this class (activity_audio_to_send.xml) and layout for single row (single_list_item.xml). How can I use layout for single row? Can anyone help me? Thanks in advance to everyone!</p>