listview - How to set default fragment in android? -
i have tried several ways set default fragment 1st list item when app open's first time , last opened fragment when app not opened first time. both scenarios not working. please help.
mdrawerlist.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int stupid, long id) { // getting values selected listitem name = ((textview) view.findviewbyid(r.id.name)) .gettext().tostring(); strpath = ((textview) view.findviewbyid(r.id.email)) .gettext().tostring(); string description = ((textview) view.findviewbyid(r.id.mobile)) .gettext().tostring(); source_id = integer.parseint(description); // starting single contact activity bundle data = new bundle(); data.putstring(tag_name,name); data.putstring(tag_sources, strpath); fragment fragment = new singlecontactactivity(); fragment.setarguments(data); fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.frame_container, fragment).commit(); mdrawerlayout.closedrawer(mdrawerlist); } }); new getcontacts().execute();
fmi, didnt use switch case in program. have tried
mdrawerlist.setselection(0);
here array list adapter
listadapter adapter = new simpleadapter( mainactivity.this, navdraweritems, r.layout.list_item, new string[] { tag_name, tag_sources, tag_id }, new int[] { r.id.name, r.id.email, r.id.mobile });
navdraweritem , item in navdrawer retrieve mysql
try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node contacts = jsonobj.getjsonarray(tag_iptv); // looping through contacts (int = 0; < contacts.length(); i++) { jsonobject c = contacts.getjsonobject(i); string id = c.getstring(tag_id); string name = c.getstring(tag_name); string email = c.getstring(tag_sources); string address = c.getstring(tag_package); // tmp hashmap single contact hashmap<string, string> contact = new hashmap<string, string>(); // adding each child node hashmap key => value contact.put(tag_id, id); contact.put(tag_name, name); contact.put(tag_sources, email); contact.put(tag_package, address); // adding contact contact list navdraweritems.add(contact); } } catch (jsonexception e) { e.printstacktrace();