這是我的實現!
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, list);
listView.setAdapter(adapter);
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
和保存過程:
array = new SparseBooleanArray();
array = listView.getCheckedItemPositions();
if (array.size() == 0) {
AlertDialog.Builder adb = new AlertDialog.Builder(
ListViewCheckBoxed.this);
adb.setMessage(getString(R.string.lesson_selection))
.setCancelable(false)
.setPositiveButton("OK", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
adb.show();
} else {
departmentList = new ArrayList<String>();
for (int i = 0; i < array.size(); i++) {
if (array.valueAt(i)) {
departmentList.add(listView.getAdapter()
.getItem(array.keyAt(i)).toString());
}
}
}
檢查ApiDemos,對於多選列表視圖的示例。 – Qberticus
是的,沒有執行如何獲得所述選擇 – ChuckKelly