android listview 游标,Android Listview - 使用游标时无法选择多个项目
我有一個listview填充了使用SimpleCursorAdapter的游標數據.我想這樣做,所以我可以選擇多個項目,每個項目都有一個復選框,但我只能一次檢查一個項目,即每次選擇一個項目時,它將清除當前選擇的項目.
如果我使用ArrayAdapter填充列表視圖,它工作正常.我可以選擇多個項目.所以我不知道為什么它不適用于SimpleCursorAdapter.
如果重要的話,這將在DialogFragment中創建.
真的把頭發拉出來,請幫助!!
這是代碼:
Cursor attributesCursor = mDBHelper.getItemAttributesbyType(menuID, itemID, "M");
getActivity().startManagingCursor(attributesCursor);
ListView lv = new ListView(this.getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lv.setLayoutParams(params);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getActivity(), android.R.layout.simple_list_item_multiple_choice,
attributesCursor, new String[] { "AttributeDescription" },
new int[] { android.R.id.text1 },0);
attributesLinearLayout.addView(lv);
lv.setAdapter(adapter);
lv.setItemsCanFocus(false);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
編輯:只是為了添加一些額外的信息,如果我使用這個代碼,多選項列表視圖工作,其中"項目"是一個簡單的字符串數組:
lv.setAdapter(new ArrayAdapter(this.getActivity(),
android.R.layout.simple_list_item_multiple_choice, items));
此外,此listview將動態添加到包含其他控件的dialogfragment中的現有Linearlayout(attributesLinearLayout).我也嘗試擴展其他適配器,包括陣列適配器和客戶項目布局,但這又不允許我選擇多個項目.
請幫忙!!
總結
以上是生活随笔為你收集整理的android listview 游标,Android Listview - 使用游标时无法选择多个项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mpvue微信小程序动画_mpvue小程
- 下一篇: 小程序 delete_程序员崩溃的43个