2013-10-15 28 views
0

道歉,如果我錯過了一些非常簡單的東西,我對編程很陌生。什麼是Mediastore對象的一個​​很好的simpleCursorAdapter實現?

我正在嘗試構建媒體播放器,並且已經發現並使用MediaStore.Audio來收集播放列表的媒體。我現在需要實現一個適配器以將其置入列表視圖供用戶選擇。我覺得這可能是實現簡單曲目列表最優雅的方式。

到目前爲止,我有:

SimpleCursorAdapter myAdapter; 
     String[] STAR = { "*" }; 
     Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 
     String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; 

     Cursor cursor = getContentResolver().query(allsongsuri, STAR, selection, null, null); 

     if (cursor != null) { 
      if (cursor.moveToFirst()) { 
       do { 
        String song_name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); 
        int song_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); 

        String fullpath = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)); 

        String album_name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)); 
        int album_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); 

        String artist_name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); 
        int artist_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST_ID)); 
       } while (cursor.moveToNext()); 
      } 
      cursor.close(); 
     } 
    } 

我現在正在使用simpleCursorAdaptor到ListView的,但不知道如何去了解它,或者把它放在哪裏。任何幫助將不勝感激。

回答

0

您必須像執行「活動」一樣來實現自己的SimpleCursorAdapter。

MediaStoreCursorAdapter extends SimpleCursorAdapter { . . . 

將其分配給您的ListView通過

ListView myListView = (ListView) findViewById(R.id.mylistview); 

獲得活動的OnCreate對它的引用,然後分配適配器給它:

myListView.setAdapter(myAdapter); 

如果你是一個初學者,你可能會想深入瞭解一些基本教程,在深入研究之前瞭解語言和框架。

祝你好運!

+0

感謝您的時間,一旦我根據此建議嘗試了更多的東西,我會更新此主題的更多細節。似乎有幾種方法可以解決它! –

相關問題