Когда мы нажимаем на альбомы, чем должен отображаться список песен в альбоме, я пытаюсь вот так, но он отображает все песни в SD card
.
private OnItemClickListener musicgridlistener1 = new OnItemClickListener(){
public void onItemClick(AdapterView parent, View v, int position,long id)
{
System.gc();
album_column_index1 = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.AlbumColumns.ALBUM_ART);
musiccursor.moveToPosition(position);
MUSICfilename = musiccursor.getString(album_column_index1);
Log.i("=======this is file name of album========",""+musiccursor.getCount()+" "+MUSICfilename+" "+position);
String[] ablummusicproj = {MediaStore.Audio.Media.DATA,
MediaStore.Audio.AlbumColumns.ALBUM,
MediaStore.Audio.AlbumColumns.ARTIST,
MediaStore.Audio.Media.DISPLAY_NAME};
final String sortOrder = MediaStore.Audio.Media.ALBUM_KEY + " COLLATE LOCALIZED ASC";
//final String sortOrder= MediaStore.Audio.Media.ALBUM_KEY + " ASC, "
// + MediaStore.Audio.Media.TRACK + " ASC, "
// + MediaStore.Audio.Media.TITLE_KEY + " ASC";
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
musicAlbum = getBaseContext().getContentResolver().query(uri, ablummusicproj, null, null, sortOrder);
count = musicAlbum.getCount();
Log.i("++++++++++ value of album cursor is ",""+count);
gridmusic = (GridView) findViewById(R.id.gridmusic);
madAdapter_internal = new MusicalbumAdapter_internal(getApplicationContext());
gridmusic.setAdapter(madAdapter_internal);
gridmusic.setOnItemClickListener(musicgridlistener);
musiccursor=musicAlbum;
}
};
MusicalbumAdapter_internal
Класс
public class MusicalbumAdapter_internal extends BaseAdapter {
private Context maContext;
public MusicalbumAdapter_internal(Context c) {
maContext = c;
Log.i("++++++++++++++++++", "this is context");
}
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 tv1 = new TextView(maContext.getApplicationContext());
String id = null;
if (convertView == null) {
music_column_index = musicAlbum.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DISPLAY_NAME);
musicAlbum.moveToPosition(position);
id = musicAlbum.getString(music_column_index);
//music_column_index = musiccursor
//.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE);
musicAlbum.moveToPosition(position);
//id += " Size(KB):" + musiccursor.getString(music_column_index);
tv1.setLayoutParams(new GridView.LayoutParams(100, 100));
tv1.setText(id);
} else
tv1 = (TextView) convertView;
return tv1;
}
}