I’m facing a weird problem that I did not find for it any explanation, I’ll comment in code as follows:
final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String,Object> map = new HashMap<String,Object>();
//for example payss ArrayList contains `A,B,C,D,E,F,G`
for (int i=0;i<payss.size();i++){
Bitmap contact_pic=pays_drapeaux.get(i);
drawable=new BitmapDrawable(contact_pic);
map.put("pays", payss.get(i).getNom());
Log.i("PAYS",payss.get(i).getNom()); //here it shows correctly the values one by one
map.put("drapeau",drawable);
list.add(map);
}
//here want to show what the list contains after setting it above
for (int i=0;i<list.size();i++){
Log.i("VALUES",list.get(i).values().toString()); //but here it shows G,G,G,G,G,G,G
}
As you can see i have at the end a list variable with all its values the recent payss value (G). Any idea why i’m facing that problem.
Thank you for helping.
You use only one
Mapobject and add it several times to the list. In the first loop the entries are always overwritten (since there is only one map). So clearly just the last values survive.