這是我的列表佈局:如何實現複選框ListView中的Android刪除時listItems
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:id="@+id/linearLayout2"
android:layout_height="fill_parent">
<CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content"
android:layout_height="wrap_content"></CheckBox>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/linearLayout3" android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:text="TextView" android:id="@+id/row1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="TextView" android:id="@+id/row2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
雖然我有多餘的佈局,這一切是一個複選框和一對夫婦TextViews的。我希望每個listItem都是可點擊的(就像去一個不同的意圖一樣),但是當我在我的活動中單擊一個按鈕(DELETE BUTTON)時,我希望能夠顯示覆選框並選擇要刪除和刪除的項目。示例代碼讚賞。
Java代碼:
adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
from, to);
listthings.setAdapter(adapter);
listthings.setOnItemClickListener(this);
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(this, Item1.class);
intent.putExtra("com.painLogger.painLevel", painLevelString);
intent.putExtra("com.painLogger.painTime", timeOfPainString);
intent.putExtra("com.painLogger.treatment", textTreatmentString);
intent.putExtra("painLocation", painLocation);
startActivity(intent);
}
這在SO上已經問過很多次了。 –