I am trying to display multiple column of media store like artist,album,title etc .I am able to get one of the column in arraylist properly and it is working but when I add the other column I am getting all the column in the same array list so I made a class and adding the column in that class method .But i am not able to declare it in the custome adapter here is my code.
Activity main
private ArrayList < MediaFileInfo > audioList = new ArrayList < > ();
private void External() {
try {
String[] proj = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM
}; // Can include more data for more details and check it.
String selection = MediaStore.Audio.Media.DURATION + ">=90000";
String[] selectionArgs = null;
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, selectionArgs, sortOrder);
if (audioCursor != null) {
if (audioCursor.moveToFirst()) {
do {
int audioTitle = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
int audioartist = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
int audioalbum = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
MediaFileInfo info = new MediaFileInfo();
info.setTitle(audioCursor.getString(audioTitle));
info.setAlbum(audioCursor.getString(audioalbum));
info.setArtist(audioCursor.getString(audioartist));
audioList.add(info);
} while (audioCursor.moveToNext());
}
}
audioCursor.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Method class
public class MediaFileInfo {
private String title, artist, album;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getAlbum() {
return album;
}
public void setAlbum(String album) {
this.album = album;
}
}
CustomeAdapter
public class CustomeAdapter extends ArrayAdapter {
private ArrayList < MediaFileInfo > audioList = new ArrayList < > ();
public CustomeAdapter(Context context, int resource) {
super(context, resource);
}
public CustomeAdapter(MainActivity context, ArrayList < MediaFileInfo > audioList) {
super(context, R.layout.custome_list, audioList);
}
@
Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater imthebest = LayoutInflater.from(getContext());@
SuppressLint("ViewHolder") View custome = imthebest.inflate(R.layout.custome_list, parent, false);
MediaFileInfo item = audioList.get(0);
String item1 = (String) getItem(position);
TextView text1 = (TextView) custome.findViewById(R.id.textView);
text1.setText(item1);
return custome;
}
}
custome xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Song name"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Artist"
android:id="@+id/textView2" />
</LinearLayout>
how to set the methods as an array .how i can get the method any example will be helpful