android - Return to a fragment stateless -
i have 3 fragments a, b(with search) , c. want fragment b on key pressed c, not retained state/with nothing in search bar precisely.
here did:
public class fragcount extends fragment{ //expandablelistadapter listadapter; // searchableadapter listadapter; expandablelistview explistview; list<string> listdataheader; hashmap<string, list<string>> listdatachild; private int groupid = -1; public static edittext searchtext; @override public view oncreateview(layoutinflater inflater,viewgroup container, bundle args) { view view = inflater.inflate(r.layout.country_main, container, false); setretaininstance(true); // listview explistview = (expandablelistview) view.findviewbyid(r.id.lvexp); // preparing list data preparelistdata(); listadapter = new searchableadapter(getactivity(), listdataheader, listdatachild); // setting list adapter explistview.setadapter(listadapter); explistview.setonchildclicklistener(new expandablelistview.onchildclicklistener() { public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { final string selected = (string) listadapter.getchild( groupposition, childposition); values.language = selected; getactivity().getwindow().setsoftinputmode( windowmanager.layoutparams.soft_input_state_always_hidden); explistview.collapsegroup(-1); bundle args = new bundle(); args.putstring("menu", selected); args.putint("serial",childposition); fragment c = new infoshow(); c.setarguments(args); explistview.collapsegroup(groupid);
calling fragment c
fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.content_frame,c).addtobackstack(null).commit(); return true; } }); searchtext = (edittext) view.findviewbyid(r.id.inputsearch); searchtext.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence charsequence, int i, int i2, int i3) { } @override public void ontextchanged(charsequence charsequence, int i, int i2, int i3) { } @override public void aftertextchanged(editable editable) { fragcount.this.listadapter.getfilter().filter(editable.tostring()); listadapter.notifydatasetchanged(); explistview.invalidateviews(); explistview.collapsegroup(groupid); } }); ((actionbaractivity) getactivity()).getsupportactionbar().settitle("select country"); explistview.setongroupexpandlistener(new expandablelistview.ongroupexpandlistener() { int previousgroup = -1; @override public void ongroupexpand(int groupposition) { if(groupposition != previousgroup) explistview.collapsegroup(previousgroup); previousgroup = groupposition; groupid = previousgroup; } }); return view; }
Comments
Post a Comment