アイテムのリストを表示するAndroid 4以前のウィジェットが動作しています。各項目には、3 つの色のいずれかを示すカラー パッチと、アプリ データの属性によって色とスタイルが決定されるテキストがあります。リストは垂直 LinearLayout として実装されていますが、ICS でウィジェットをスクロール可能にするために ListView に変換したいと考えています。ListView を使用している場合、基になるアイテム データ プロパティをアイテム リモート ビューにマップする方法がわかりませんでした。
(以下のコードは簡略化されています)。
アイテムのデータクラスは
class ItemData {
String text;
int textColor;
int patchColor;
}
ウィジェットのトップレイアウトは
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_top_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/widget_item_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
// Items are added here at runtime by my widget provider class.
</LinearLayout>
</FrameLayout>
そして、各アイテムビューはこのレイアウトを使用します
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/widget_item_color"
// background color is set at runtime by the widget provider based
// on patchColor member of the item data.
android:layout_width="6dip"
android:layout_height="fill_parent"
>
</FrameLayout>
<TextView
android:id="@+id/widget_item_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
// Actual color is set at runtime by the widget provider based on
// item data.
android:textColor="@color/color_place_holder"
android:background="@android:color/transparent"
// May be set at runtime to false, based on user's prefernces.
android:singleLine="true"
android:scrollHorizontally="false"
android:ellipsize="end"
>
</TextView>
</LinearLayout>
私の質問は、トップ レイアウトの LinearLayout を ListView に変更した場合、アイテム データをアイテム ビュー プロパティにマップするロジックをどこにプラグインすればよいかということです。同様のマッピングを行うサンプル コードはありますか?