0

こんにちは、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" />
4

1 に答える 1

0

カスタム セル UI を備えた独自のカスタム アダプターを取得するには、BaseAdapter を拡張する必要があると思います。アイコンをロードするには、AsyncTask を使用します。

于 2012-10-29T16:57:17.240 に答える