0

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

数据库有这些列:

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 上照片的 uri。

    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 字节分配内存不足”。(当我尝试使用上面未更改的代码时出现此错误。)

4

1 回答 1

0

但是,我不知道如何打开 ImageView,因此我可以解压缩它,因为此错误“20155408 字节分配内存不足”。(当我尝试使用上面未更改的代码时出现此错误。)

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

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

这样你的位图将是 width/4 和 height/4

于 2013-06-09T12:51:11.820 回答