android - can't create multiple choice listview -
this code can't create multiple choice mode listview. data fetched jason , set in listview. want multiple selection choice mode on list view
public class examview extends listactivity{ private progressdialog pdialog; intent activity; // url contacts json // json node names private static final string tag_usermst = "products"; private static final string tag_qid = "que_id"; private static final string tag_que = "question"; private static final string tag_qans = "ans"; jsonarray products = null; // hashmap listview arraylist<hashmap<string, string>> contactlist; protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.user_activity_lv); contactlist = new arraylist<hashmap<string, string>>(); listview lv = getlistview(); new getcontacts().execute(); } private class getcontacts extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); // showing progress dialog pdialog = new progressdialog(examview.this); pdialog.setmessage("exam paper downloading..."); pdialog.setcancelable(false); pdialog.show(); } @override protected void doinbackground(void... arg0) { // creating service handler class instance servicehandler sh = new servicehandler(); // making request url , getting response string jsonstr = sh.makeservicecall(url, servicehandler.get); log.d("response: ", "> " + jsonstr); if (jsonstr != null) { try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node products = jsonobj.getjsonarray(tag_usermst); // looping through contacts (int = 0; < products.length(); i++) { jsonobject c = products.getjsonobject(i); string queid = c.getstring(tag_qid); string que = c.getstring(tag_que); string queans = c.getstring(tag_qans); // tmp hashmap single contact hashmap<string, string> product = new hashmap<string, string>(); // adding each child node hashmap key => value product.put(tag_qid,queid); product.put(tag_que, que); product.put(tag_qans, queans); // adding contact contact list contactlist.add(product); } } catch (jsonexception e) { e.printstacktrace(); } } else { log.e("servicehandler", "couldn't data url"); } return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); // dismiss progress dialog if (pdialog.isshowing()) pdialog.dismiss(); /** * updating parsed json data listview * */ listadapter adapter = new simpleadapter( examview.this, contactlist, r.layout.user_list_item_lbl, new string[] { tag_qid, tag_que, tag_qans }, new int[] { r.id.name, r.id.email, r.id.mobile }); setlistadapter(adapter); } }
getlistview().setchoicemode(listview.choice_mode_multiple); setlistadapter(new arrayadapter<string>(mainactivity.this,android.r.layout.simple_list_item_multiple_choice, array_sort));
use code working me. here array_sort arraylist i.e. list of items displayed. multiple items can selected this.
Comments
Post a Comment