[英]Android ListView custom icons
Hey I'm trying to add icons to my ListView. 嘿,我试图将图标添加到我的ListView。 This is how looks my ListAdapter. 这是我的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);
And this is how I get my icon 这就是我获取图标的方式
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();
}
How should I add icon to my ListView ? 如何将图标添加到ListView中? I tried to use some on internet used examples but there it looks ListAdaptar and ArrayList is built completely different way. 我尝试在互联网使用的示例中使用一些示例,但看起来ListAdaptar和ArrayList的构建方式完全不同。
My list item xml file. 我的清单项目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" />
I think you need to extend BaseAdapter to get your own custom adapter with custom cell UI. 我认为您需要扩展BaseAdapter以获得具有自定义单元UI的自定义适配器。 and to load an icon use AsyncTask. 并使用AsyncTask加载图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.