如何在列表视图中显示媒体标题?

时间:2017-12-25 19:20:53

标签: android arraylist media android-contentprovider

如何从COntentResolver获取媒体标题。我试过但它没用,我想在listView中显示媒体标题。

Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
      int ind = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
      do {
        String T = cursor.getString(ind);
        abcl.add(T);
        Log.i("SOngName", T);
      } while (cursor.moveToNext());
    }

但是这给了我IndexOutOfBondsExceptions的错误,我的错误logcat是

please any one guide , thanks

1 个答案:

答案 0 :(得分:0)

首先,你应该去android 中的光标文档。它会告诉你使用游标后不是null检查;你必须将光标移动到传入结果集的第一行的开头。

Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
if(cursor.MoveToFirst()){
      int ind = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
      do {
        String T = cursor.getString(ind);
        abcl.add(T);
        Log.i("SOngName", T);
      } while (cursor.moveToNext());
  }
}