【问题标题】:Android ListView of videos available on device设备上可用视频的 Android ListView
【发布时间】:2013-12-31 12:45:42
【问题描述】:

下面的代码不起作用,应用程序在启动时关闭并出现“不幸...”错误。

protected void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan_media_store_list_view);

    vedio_list = (ListView) findViewById(R.id.vedio_list);

    Uri contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;

    String[] projection = { MediaStore.Video.VideoColumns.DISPLAY_NAME};

    cursor = getContentResolver().query(contentUri, projection, null, null, null);

    title_index = cursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.TITLE);

    al = new ArrayList<String>();

    showList();
   }

private void showList() {

    while(cursor.moveToNext())
    {
        String title = cursor.getString(title_index);

        al.add(0 , title);
        aa.notifyDataSetChanged();
    }
    cursor.close();

}

我做错了什么?

【问题讨论】:

  • 请张贴logcat
  • 什么是“不幸的错误”??????

标签: android listview android-contentprovider mediastore


【解决方案1】:

通过获取计数检查光标是否良好并移动到列表中的第一个:

private void showList() {
if(cursor.getCount() > 0){
   cursor.moveToFirst();
   while(cursor.moveToNext())
     {
    String title = cursor.getString(title_index);
    al.add(0 , title);
    aa.notifyDataSetChanged();
     }
 }
cursor.close();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2014-01-16
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    相关资源
    最近更新 更多