How to display images stored in database as blob in Listview in Android?

My question here is that I am creating a small quiz to get the image above and its answer right below it. All this is done in a new action, where I want to show the answers to the quiz. There are about 40 questions, each with an image. Therefore, I tried using HashMap as follows: -

   ListView lv = (ListView)findViewById(R.id.list1);
   String[] from = new String[] {"ques","ans"};
   int[] to = new int[] {R.id.ques, R.id.ans};

           // prepare the list of all records
    List<HashMap<String,Bitmap>> fillMaps = new ArrayList<HashMap<String,Bitmap>>();
     Cursor c1 = db.getQues(4);
     byte[] bb = c1.getBlob(0);
     Bitmap image = BitmapFactory.decodeByteArray(bb, 0, bb.length);
     //Cursor c2 = db.getAns(4);
    // String ans1 ="Ans"+") "+c2.getString(0);
     HashMap<String,Bitmap> map = new HashMap<String, Bitmap>();
    // HashMap<String,String> map1 = new HashMap<String, String>();
     map.put("ques",image);
    // map1.put("ans",ans1);
     fillMaps.add(map);      

     SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.itemsign, from, to);
     lv.setAdapter(adapter);

But I could not find a way to implement it correctly. This code does not work. It just shows a blank page. So any help would be greatly appreciated. Since I'm new to android, please be more detailed when explaining.

+3
source share
1 answer

, , - . javadoc SimpleAdapter:

public SimpleAdapter ( , > , int , String [] from, int [] to)

: API 1

  • , , SimpleAdapter
  • . . , "from"
  • , . , , , ""
  • , , .
  • to , "from". TextViews. N N from.

Bitmap SimpleAdapter, :)

+1

All Articles