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

问题描述 投票:0回答:1

如何从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

android arraylist media android-contentprovider
1个回答
0
投票

首先,你应该去android中的Cursor Documentation。它会告诉你使用游标后不是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());
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.