【问题标题】:Android ListView custom iconsAndroid ListView 自定义图标
【发布时间】:2012-10-29 16:55:19
【问题描述】:

嘿,我正在尝试将图标添加到我的 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" />

【问题讨论】:

  • 每个列表项的图标是否不同?

标签: android listview icons


【解决方案1】:

我认为您需要扩展 BaseAdapter 以使用自定义单元 UI 获得您自己的自定义适配器。并使用 AsyncTask 加载图标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 2011-09-12
    • 2015-03-28
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多