我有简单的名单将在从数据库中充满还有一个复选框。我需要一个手柄,所有选中的复选框。 WHN CLEAR键是pssed在这一点上我需要的所有选中的复选框行ID删除它们$ P $。做这个事情 : 我list.xml文件看起来是这样的:
I have simple list to be filled in from the database along with a checkbox. I need a handle to all the checkboxes selected. Whn the CLEAR button is pressed at that point I need the row ids of all the selected check boxes to delete them. To do this : My list.xml file looks like this :
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clearselected"
android:text="CLEAR"
android:clickable ="false"/>
</LinearLayout>
和我的data_entry.xml是这样的:
and my data_entry.xml looks like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/CheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50px"
android:layout_y="22px"></CheckBox>
<TextView android:text="@+id/EntryText"
android:id="@+id/EntryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/blue"/>
</LinearLayout>
现在:我有list.java文件我在哪里填充名单如下:
Now: I have list.java file where I am populating the list as follows:
private void populateList() {
Cursor c = db1.getAllList();
String[] fields = new String[]{db1.get_data()};
SimpleCursorAdapter cursorAdapter = new
ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.data_entry, c,
fields, new int[] {R.id.EntryText});
setListAdapter(adapter);
}
现在我在哪里得到的句柄heckbox引起其他地方的data_entry包含复选框它会给我一个空的异常。另外,我需要一个监听器来处理的复选框状态?我只是停留在这一点上,没有线索。
Now where do i give the handle to the heckbox cause anywhere else it would give me a null exception as the data_entry contains the checkboxes. Plus I need a listener to handle the checkbox status? I am just stuck at this point with no clue..
而不是滚动您自己,为什么不直接使用标准的ListView与CHOICE_MODE_MULTIPLE启用?
Rather than rolling your own, why not just use a standard ListView with CHOICE_MODE_MULTIPLE enabled?
listView.setChoiceMode(CHOICE_MODE_MULTIPLE);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, fields));
您可以再问问ListView控件的检查项目。
You can then ask the listView for the checked items.
listView.getCheckedItemPositions();