我试图显示像艺术家,专辑,标题等多媒体商店的专栏。我能够得到arraylist列中的一个正确,它正在工作,但是当我添加另一列我得到的所有列在同一个数组列表中,所以我创建了一个类,并在该类方法中添加了列。但我无法在custome适配器中声明它 这是我的代码。如何设置数组的方法
活动主
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类
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>
如何设置方法为数组。如何,我可以得到任何方法例如将有助于
你会得到什么错误? – Jokab
我不能将方法设置为我尝试给定的方式 –