【发布时间】:2011-12-22 01:23:19
【问题描述】:
我正在尝试在我的 ExpandableList 的一行中添加一个小图像。下面你可以看到我的自定义适配器的getchildview方法的代码。它非常适合设置动态文本,但是当我想添加图像时它会失败。
我不明白为什么应用程序会完全忽略添加图像的命令。我尝试了 2 个版本,但都失败了。
我没有收到任何运行时错误,只是没有加载图像。 此外,我知道至少“setImageBitmap”有效,因为我在其他地方成功使用了它。
引用的图像是 9x10 png 文件。
请帮助我,因为我认为我没有遗漏任何东西,但图像根本没有显示。
我尝试在 relativelayout l 上设置背景颜色(setBackgroundColor),但它也没有效果。所以我认为这是与图形相关的东西,但我在我的方法中找不到任何错误。
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
RelativeLayout l = (RelativeLayout) getLayoutInflater().inflate(R.layout.titoli2_gruppo_riga, null)
String s;
s=prodotti.get(groupPosition).get(childPosition)[DSP];
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.disponibile);
if(s.equals("true"))
((ImageView) l.findViewById(R.id.tgr_dispon)).setImageBitmap(bm);
else
((ImageView) l.findViewById(R.id.tgr_dispon)).setImageResource(R.drawable.nondispon);
((TextView) l.findViewById(R.id.tgr_descr)).setText(prodotti.get(groupPosition).get(childPosition)[DES]);
((TextView) l.findViewById(R.id.tgr_prezz)).setText("€"+prodotti.get(groupPosition).get(childPosition)[PRE]);
((TextView) l.findViewById(R.id.tgr_note)).setText(prodotti.get(groupPosition).get(childPosition)[NOT]);
((TextView) l.findViewById(R.id.tgr_sigla)).setText(prodotti.get(groupPosition).get(childPosition)[SIG]);
return l;
}
你可以看到我正在膨胀的 XML,这里是 http://pastebin.com/DwxdxJSK
【问题讨论】:
标签: android xml image layout bitmap