Search code examples
javaandroidsimpleadapter

Android - How I can put different Image resources to the SimpleAdapter?


I'm creating a SimpleAdapter with this code


String[] from = { ATTRIBUTE_NAME_TEXT, ATTRIBUTE_NAME_CHECKED,   ATTRIBUTE_NAME_IMAGE };
int[] to = { R.id.tvText, R.id.cbChecked, R.id.ivImg };
SimpleAdapter sAdapter = new SimpleAdapter(this, data, R.layout.item,from, to);
lvSimple = (ListView) findViewById(R.id.lvSimple);  
lvSimple.setAdapter(sAdapter);`

But I need an individual icon for each item

if(checkData()) return R.drawable.img0;
else return R.drawable.img1;

How I can do that trick without writing custom adapter?


Solution

  • You do not need put different Image resources to the SimpleAdapter. you Just put different size in android different folder(mdpi, hdpi) with same name. Android automatically take correct according to android device size.

    Thanks