android - How to get a column value of item in ListView when I use CHOICE_MODE_MULTIPLE mode and ArrayAdapter<String>? -
i hope use string aa=c.getstring(c.getcolumnindex("address"))
column value of item in function private void setselectedandtotal
.
app crash, how can do? thanks!
private listview lv; private textview selectedandtotal; private void initlistview() { list<string> msglist = getsms(); 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(arg2); } }); } private void setselectedandtotal(int arg2){ cursor c = (cursor) lv.getitematposition(arg2); string aa=c.getstring(c.getcolumnindex("address")); selectedandtotal.settext(aa); } public list<string> getsms() { list<string> sms = new arraylist<string>(); uri urismsuri = uri.parse("content://sms/inbox"); 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; }
string aa=c.getstring(c.getcolumnindex("address")); selectedandtotal.settext(aa);
if no such column exists, returns -1
. probably, happens , passing integer argument considered resource id.
also, make sure initialized textview
before settext()
.
Comments
Post a Comment