public class MyActivity extends Activity { ArrayList<HashMap<String, Object>> arrayList; HashMap<String,Object> hashMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); arrayList= new ArrayList<HashMap<String, Object>>(); CreateHashMap(); SimpleAdapter simpleAdapter=new SimpleAdapter(this,arrayList,R.layout.item, new String[]{"TEXT","IMAGE"},new int[]{R.id.textView,R.id.imageView}); ListView listView= (ListView) findViewById(R.id.listView); listView.setAdapter(simpleAdapter); } public void CreateHashMap(){ for (int i=0; i<20; i++) { hashMap = new HashMap<String, Object>(); hashMap.put("TEXT", "asdadasdadsa"); hashMap.put("IMAGE", R.drawable.ic_launcher); arrayList.add(hashMap); } } } 

How to add a key to HashMap that allows you to specify the size of Width for IMAGE?

I thought and thought, did not think of anything, maybe you throw something?

////////////////////////////////////////////////// /////////

Why in

 class MySimpleAdapter extends SimpleAdapter { public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); } @Override public void setViewImage(ImageView v, int value) { super.setViewImage(v, value); Log.e("asd","asd"); } } 

Is setViewImage called 20 times if I create 5 objects, and called 40 times if I create 10 objects? This is normal? Or should it not be so?

    1 answer 1

    Create a class that stores the necessary data for the list item, and do not pervert with these crutches with Mapa

    • @metalurgus, I did not understand a word. - Futurama
    • @Futurama, well, you store all the necessary data for each list item in the hashmepe. Instead, create a class that will contain all the necessary data. - Vladyslav Matviienko