[英]Android ListView custom icons
嘿,我试图将图标添加到我的ListView。 这是我的ListAdapter的外观。
ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.list_item,
new String[] { KEY_NAME, Icon }, new int[] {R.id.name, R.id.icon});
setListAdapter(adapter);
这就是我获取图标的方式
String imgFilePath = ASSETS_DIR + ICON_NAME;
try {
Bitmap bitmap = BitmapFactory.decodeStream(this.getResources().getAssets()
.open(imgFilePath));
Icon.setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如何将图标添加到ListView中? 我尝试在互联网使用的示例中使用一些示例,但看起来ListAdaptar和ArrayList的构建方式完全不同。
我的清单项目xml文件。
<ImageView
android:id="@+id/myicon"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#dc6800"
android:textSize="16sp"
android:textStyle="bold"
android:paddingTop="6dip"
android:paddingBottom="2dip" />
我认为您需要扩展BaseAdapter以获得具有自定义单元UI的自定义适配器。 并使用AsyncTask加载图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.