1

私は持っていListViewます:

...

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="?android:attr/colorBackground"
    android:cacheColorHint="?android:attr/colorBackground"
    android:choiceMode="singleChoice"
    android:drawSelectorOnTop="false"
    android:fadingEdge="none"
    android:fastScrollEnabled="true"
    android:scrollingCache="true" />

...

リスト項目のレイアウト:

...

<ImageView
    android:id="@+id/folder_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="5dip"
    android:paddingTop="3dip"
    android:src="@drawable/icon_folder" />

<TextView
    android:id="@+id/fol_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/folder_image"
    android:textSize="22dip" />

...

ListView、 を使用してデータベースから読み込まれますsetListAdapter(SimpleCursorAdapter)。行ごとに画像(フォルダアイコン)を表示したい。ただし、2 つの特定の行 (たとえば、ある種のインジケーターを使用して行を識別する方法を知っていると仮定) については、異なる画像を表示したいと考えています。不明な数のフォルダーがあり、フォルダーの名前の横に各行のフォルダー アイコンが表示されるとします。また、たとえば、Word 文書と Excel ファイルがそれぞれ 1 つずつあり、それぞれに適切な画像を表示したいとします。

4

1 に答える 1

0

ステルスコプターが書いたものと同様に、アイコン選択アルゴリズムを実装するには、拡張SimpleCursorAdapterおよびオーバーライドする必要があります。これは、テクニックについて説明しているbindView()の本の 1つからの無料の抜粋です。

于 2010-09-08T10:16:41.217 に答える