2011-10-26 43 views
3

我有一個小問題,使用簡單的適配器將圖像設置爲列表視圖。我是從SD卡使用ID從SQLite數據庫獲取圖像,所以sqlite的語句工作時,圖像上的SD卡,但如果我嘗試設置他們在我的列表視圖,它給我的輸出:Android SimpleAdapter添加圖像到列表視圖

resolveUri failed on bad bitmap uri: [email protected] 
LogCat上的

。下面是我用做它的代碼:

String sqlite2 = "SELECT objectId FROM collectionmedias WHERE collectionId="+collId+" AND mediaType="+fronImage; 
      Cursor bg = userDbHelper.executeSQLQuery(sqlite2); 
      if (bg.getCount() == 0) { 
       Log.i("", "No Image file"); 
       bg.close(); 
      } else if (bg.getCount() > 0) { 
       for (bg.move(0); bg.moveToNext(); bg.isAfterLast()) { 

        objectId = Integer.parseInt(bg.getString(bg.getColumnIndex("objectId"))); 
        Log.i("","objectId : "+objectId); 
        path = Environment.getExternalStorageDirectory() 
          + "/.MyApp/MediaCollection/" + objectId + ".png"; 
        Log.v("","path: "+path); 

       } 
      } 

      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inTempStorage = new byte[2*1024]; 

      Bitmap ops = BitmapFactory.decodeFile(path, options); 



      hm = new HashMap<String, Object>(); 
       hm.put(IMAGE, ops); 
       hm.put(TITLE, text); 
       hm.put(CARDS_COUNT, cardsCount +" MyApp"); 
       items.add(hm); 
     } 

     final SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.main_listview, 
       new String[]{TITLE, CARDS_COUNT, IMAGE}, new int[]{ R.id.main_name, R.id.main_info, R.id.main_img}); 
     listView.setAdapter(adapter); 

回答

2

我固定它使用這樣的:path = Environment.getExternalStorageDirectory() + "/MyApp/MediaCollection/" + objectId + ".png";

+1

我有同樣的問題,但我的方法略有不同,因爲我使用的下載圖像方法,而不是位圖廠。請看看我的問題:http://stackoverflow.com/questions/13450432/using-simpleadapter-with-image-for-listview –