0

ListView に問題があります。オブジェクトとは異なる値を含めたい。私のオブジェクトアイテムには4つの属性があります:

String name;
int number;
int price;
boolean check;

これは私のコードです:

ArrayList<Item> list = new ArrayList<Item>();
list.add(new Item("hej", 1, 1, false));
list.add(new Item("farvel", 2, 2, true));
setListAdapter(new ArrayAdapter<Item>(this, R.layout.list_item, R.id.tv, list));

ListView lv = getListView();
lv.setTextFilterEnabled(true);

ここで、true/false をこの XML のチェックボックスにリンクする必要があります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<CheckBox
    android:id="@+id/cb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

</LinearLayout>

私は本当にあなたの助けが欲しいです!!

4

1 に答える 1

0

そのためには、独自のアダプターを作成する必要があります。

基本的に、アダプタ クラスの 1 つを拡張し、(必要に応じて) 次のメソッドをオーバーライドします。

getCount
getItem
getItemId
getView

いくつかのガイド/チュートリアルが浮かんでいます:

そう質問

アダプタ チュートリアル 1

カスタム ArrayAdapter の例

幸運を!

于 2012-05-19T20:20:10.480 に答える