我想获取 android 设备中所有音乐文件的列表,所以我使用了以下代码
public class MusicAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater l_Inflater;
public MusicAdapter(Context c) {
mContext = c;
l_Inflater = LayoutInflater.from(c);
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv = new TextView(mContext.getApplicationContext());
String id = null;
TextView txt_itemName = null;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.menu, null);
txt_itemName = (TextView) convertView.findViewById(R.id.textView1);
ImageView itemImage = (ImageView) convertView.findViewById(R.id.imageView1);
music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
musiccursor.moveToPosition(position);
id = musiccursor.getString(music_column_index);
txt_itemName.setText(id);
} else {}
return convertView;
}
}
一切正常但是当我上下滚动时,列表混淆了。我点击一个标题,但它播放错误的标题。每次我回到列表顶部时,都会显示不同的歌曲作为第一首歌曲。我该怎么办.. ??我该如何解决这个问题