开发者

ListView with complex items, how to know the state of items?

I have LinearLayout:

<LinearLayout
  xmlns:android= "http://schemas.android.com/apk/res/android"
  android:layout_width= "fill_parent"
  android:layout_height= "fill_parent">
<TextView android:id="@+id/DictLink" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView>
<CheckBox android:text="" android:id= "@+id/DictTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" ></CheckBox>
</LinearLayout>

It used as Item in ListView. Code below create a array adapter for ListView.

ArrayList< HashMap< String, String >> adapter_list = new ArrayList< HashMap< String, String > >();

    for ( String dict : dict_list )
    {
      String [ ] data = dict.split( ";" );
      HashMap< String, String > adapter_entry = new HashMap< String, String >();
      adapter_entry.put( FIELD_TITLE, data[ 0 ] );
      adapter_entry.put( FIELD_LINK, data[ 2 ] );
      adapter_list.add( adapter_entry );
 开发者_开发问答   }

    String [ ] from =
    { FIELD_TITLE, FIELD_LINK };
    int [ ] to =
    { R.id.DictTitle, R.id.DictLink};

    final ListAdapter adapter = new SimpleAdapter( this, adapter_list, R.layout.dict_list_item , from, to );

How can I know which checkboxes are checked and which not?


The ListView class has functions that will help you:

int ListView.getCheckedItemPosition() (for single-selection lists) SparseBooleanArray ListView.getCheckedItemPositions() (for multi-selection lists)

And more: http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemIds()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜