Refresh fragment in Android -
i have 2 tabs , each has 1 fragment. each fragment has recycler views. have action bar , have search property in (i'm using materialsearchview). want search data in each fragment when app loading, search working first fragment, if swipe next fragment , come first fragment search not working because methods related first fragment not getting called. how call them when user in first fragment.
public class tab1fragment extends fragment { private static final string tag = "tab1fragment"; context c; string user_name,password; materialsearchview materialsearchview; string url = null; recyclerview rv1; tablelayout tablayout; @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { setuservisiblehint(false); view view = inflater.inflate(r.layout.tab1_fragment,container,false); tablayout=(tablelayout) view.findviewbyid(r.id.tablelayout); final tablelayout tablayout1=(tablelayout)view.findviewbyid(r.id.tablelayout1); final tablelayout tablayout2=(tablelayout)view.findviewbyid(r.id.tablelayout2); materialsearchview = (materialsearchview)getactivity().findviewbyid(r.id.search_view); sharedpreferences sharedpreferences=this.getactivity().getsharedpreferences("postman", context.mode_private); user_name=sharedpreferences.getstring("username","nothing"); password=sharedpreferences.getstring("password","nothing"); rv1 = (recyclerview) view.findviewbyid(r.id.mrecycler1); rv1.setlayoutmanager(new linearlayoutmanager(c)); rv1.setitemanimator(new defaultitemanimator()); download2 d2 = new download2(getactivity(),url,rv1,user_name,password,tablayout,materialsearchview); d2.execute(); return view; } other fragment is: public class tab3fragment extends fragment { private static final string tag = "tab3fragment"; string user_name,password; context c; materialsearchview materialsearchview3; recyclerview rv, rv1; tablelayout tablayout1 , tablayout; @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { setuservisiblehint(false); view view = inflater.inflate(r.layout.tab3_fragment,container,false); tablayout1=(tablelayout)view.findviewbyid(r.id.tablelayout1); materialsearchview3 = (materialsearchview)getactivity().findviewbyid(r.id.search_view); sharedpreferences sharedpreferences=this.getactivity().getsharedpreferences("postman", context.mode_private); user_name=sharedpreferences.getstring("username","nothing"); password=sharedpreferences.getstring("password","nothing"); rv = (recyclerview) view.findviewbyid(r.id.mrecycler); rv.setlayoutmanager(new linearlayoutmanager(c)); rv.setitemanimator(new defaultitemanimator()); return view; } @override public void setmenuvisibility(boolean menuvisible) { super.setmenuvisibility(menuvisible); if(menuvisible) { download3 d3 = new download3(getactivity(),url,rv,user_name,password,tablayout1, materialsearchview3); d3.execute(); } } }
Comments
Post a Comment