5
我有簡單的列表,從數據庫中有一個複選框一起填寫。我需要處理所有選中的複選框。在此時按下CLEAR按鈕時,我需要選中所有複選框的行ID來刪除它們。要做到這一點: 我list.xml文件看起來像這樣:的Android清單和複選框
< 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看起來是這樣的:
<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文件名單如下:
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包含複選框它會給我一個空例外。另外我需要一個偵聽器來處理複選框的狀態?我只是停留在這一點上,沒有頭緒..
謝謝,這就是我沒有考慮。那麼我現在有另一個問題。在我的情況下,我的光標如下: private static String [] fields;遊標c = db1.getAllList(); setListAdapter(新ArrayAdapter(此,android.R.layout.simple_list_item_multiple_choice,字段)); final ListView listView = getListView(); \t listView.setItemsCanFocus(假); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 我如何從光標場陣列價值觀 當使用簡單的遊標適配器時,我傳遞了錯誤嗎? 感謝Prerna –
Prerna
2010-06-25 18:23:47
謝謝!這真的幫了我很多。我遇到過同樣的問題。但現在我知道如何做到這一點。 – 2011-09-22 13:13:17