简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM