android - ArrayAdapter<String> doesn't support getCheckedItemIds()? -
i hope use lv.getcheckeditemids().length sum of selected items. seems arrayadapter doesn't support getcheckeditemids(), right?
private void initlistview(int pos) { list<string> msglist = getsms(pos); arrayadapter<string> adapter2 = new arrayadapter<string>(this, android.r.layout.simple_list_item_multiple_choice, msglist); lv.setadapter(adapter2); lv.setchoicemode(listview.choice_mode_multiple); lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { setselectedandtotal(); } }); } private void setselectedandtotal(){ selectedandtotal.settext(lv.getcheckeditemids().length+ "/" + lv.getcount()); } public list<string> getsms(int pos) { list<string> sms = new arraylist<string>(); uri urismsuri = uri.parse(valuelist.get(pos)); cursor cur = getcontentresolver().query(urismsuri, null, null, null, null); while (cur.movetonext()) { string address = cur.getstring(cur.getcolumnindex("address")); string body = cur.getstring(cur.getcolumnindexorthrow("body")); sms.add("number: " + address + " .message: " + body); } return sms; }
here snippet documentation on using getcheckeditemids():
the result valid if choice mode has not been set choice_mode_none , adapter has stable ids. (hasstableids() == true)
by default, baseadapter (and subclass arrayadapter) not support stable item ids, if want utilize need create own subclass returns true hasstableids() , returns unique value getitemid() each element.
otherwise, you'll have use getcheckeditempositions() instead, in use case described provide same answer need without work.
Comments
Post a Comment