0

This is part of my class that i supposed to select * from a sqlite table, show them in a listview that has 4 textviews and one imageview.

database has these columns:

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

so img_loc column has uri of the photos on 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;
            }
        });

however, i dont know how to get on the ImageView so then i can decompress it due to this error "Out of memory on a 20155408-byte allocation." (i get this error when i try to use the code above unchanged.)

kevoroid
  • 5,052
  • 5
  • 34
  • 43

1 Answers1

0

however, i dont know how to get on the ImageView so then i can decompress it due to this error "Out of memory on a 20155408-byte allocation." (i get this error when i try to use the code above unchanged.)

Remember that a Bitmap needs width * heigth * 4 bytes of memory. That could be a lot. So you have to downsampling it .

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

this way your bitmap will be width/4 and height/4

Blackbelt
  • 156,034
  • 29
  • 297
  • 305