简体   繁体   English

Android-如何将不同的图像资源放入SimpleAdapter?

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

I'm creating a SimpleAdapter with this code 我用这段代码创建一个SimpleAdapter


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. 您不需要将其他图像资源放入SimpleAdapter。 you Just put different size in android different folder(mdpi, hdpi) with same name. 您只需将不同大小的同名文件放入android不同的文件夹(mdpi,hdpi)即可。 Android automatically take correct according to android device size. Android会根据android设备大小自动采取正确的措施。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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