[英]Can't capture Android Listview checkbox state
盡我所能,我根本無法檢測到Listview復選框的真/假(選中/未選中)狀態。 我正在即時構建這些,這可能是問題的一部分。
我的代碼:
使用復選框構建listview:
ArrayAdapter<String> adapter = new ArrayAdapter<String>( activity, android.R.layout.simple_list_item_multiple_choice, results); setListAdapter(adapter); for (int i = 0; i < activity.getListAdapter().getCount(); i++) { activity.getListView().setItemChecked(i, true); //doesn't work BTW
}
捕獲復選框的click事件://即使選中
@Override protected void onListItemClick(ListView lv, View view, int position, long id) { super.onListItemClick(lv, view, position, id); CheckedTextView checkBox = (CheckedTextView)this.activity.getListView().getAdapter().getView(position, view, null);
非常感謝
最高
這就是我想出的:
在我的提交邏輯中,我無法拾取復選框狀態,因此我在onItemClick中對其進行了跟蹤
unfollowerState是一個布爾數組,用於跟蹤檢查狀態...我在提交時將其選中
protected void onListItemClick(ListView lv, View view, int position, long id) {
super.onListItemClick(lv, view, position, id);
CheckedTextView checkBox = (CheckedTextView) view; //get the UI checkBox
Log.i(LOG_TAG, ".onListItemClick" + checkBox.getText() + " " + checkBox.isChecked());
unfollowerState[position-1]=checkBox.isChecked(); //record the check state
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.