在SimpleCursorAdapter中寻址ImageView以显示图像

时间:2013-06-09 12:44:53

标签: android

这是我的课程的一部分,我应该从sqlite表中选择*,在列表视图中显示它们有4个textview和一个imageview。

数据库包含以下列:

sqlite> select * from events;
_id         title       location    date        img_loc                                                        
----------  ----------  ----------  ----------  ---------------------------------------------------------------
1           office      space       today       file:///storage/sdcard0/DCIM/OrangeClubPhotos/1370701231842.jpg
2           home        street26    june        null                                                           
3           wrjjfhwiru  rkljfewlr   487598347   file:///storage/sdcard0/DCIM/OrangeClubPhotos/1370702333785.jpg
4           jojo        jiji        today       file:///storage/sdcard0/DCIM/OrangeClubPhotos/1370702372846.jpg
5           office des  camp        right now   null                                                           
6           bed         no locatio  right here  null                                                           
7           home home   nyc home    June 8      file:///storage/sdcard0/DCIM/OrangeClubPhotos/1370714226736.jpg

所以img_loc列上有sdcard上的照片。

    String[] from = new String[]{DbHandler.column_id, DbHandler.column_name, DbHandler.column_location, DbHandler.column_date, DbHandler.img_loc};
        int[] to = new int[] {R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.photoInDb};
        SimpleCursorAdapter simpleCurs = new SimpleCursorAdapter(this, R.layout.listviewfinal, c, from, to);
        listView.setAdapter(simpleCurs);
        simpleCurs.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Cursor cursor, int i) {
                return false;
            }
        });

然而,我不知道如何使用ImageView,因此我可以解压缩它由于此错误“在20155408字节分配的内存不足”。 (当我尝试使用上面的代码时,我收到此错误。)

1 个答案:

答案 0 :(得分:0)

  

然而,我不知道如何进入ImageView所以我可以   由于此错误解压缩它“在20155408字节的内存不足   分配。“(当我尝试使用上面的代码时,我收到此错误   不变。)

请记住,位图需要width * heigth * 4个字节的内存。这可能很多。所以你必须对它进行下采样。

    BitmapFactory.Options()  opt = new BitmapFactory.Options();
    opt.inSampleSize = 4;
    Bitamap bitmap =  BitmapFactory.decodeFile(pathFromDb,  opt);

这样你的位图就是宽度/ 4和高度/ 4