android - Viewpager inside a fragment is blank when a listiview item in it is clicked and redirected to another fragment -
i using viewpager inside fragment , viewpager having listview within fragment.so when list item clicked redirected fragment in same activity. when come previous fragment(viewpager) viewpager blank! why desperate solution. suggestion appreciated.
//tabs inside fragment public class tabspageradapter extends fragmentstatepageradapter { public tabspageradapter(fragmentmanager fm) { super(fm); } /* @override public fragment getitem(int position) { // getitem called instantiate fragment given page. return pagefragment.newinstance(position + 1); } @override public int getcount() { return 3; } @override public charsequence getpagetitle(int position) { return "tab " + (position + 1); }*/ @override public fragment getitem(int position) { fragment frag = null; switch (position) { case 0: frag = new full_roaster_fragment(); break; case 1: frag = new by_sport_fragment(); break; case 2: frag = new by_team_fragment(); break; case 3: frag = new video_critique_fragment(); break; } return frag; } @override public int getcount() { return 4; } @override public charsequence getpagetitle(int position) { string title=" "; switch (position){ case 0: title="full roaster"; break; case 1: title="by sport"; break; case 2: title="by team"; break; case 3: title="for video critique"; break; } return title; } }
//child fragment of viewpager
public class full_roaster_fragment extends fragment implements adapterview.onitemclicklistener { private view rootview; public static listview analystslist; public static fullroasteradapter full_roaster_adapter; public static arraylist<ics.com.ics_app.beans.analystsearchbean.teams> analysts_search_arraylist1 = new arraylist<>(); @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.fragment_full_roaster, container, false); initialization(); full_roaster_adapter = new fullroasteradapter(getactivity(), applicationglobalclass.analysts_search_arraylist); full_roaster_adapter.notifydatasetchanged(); analystslist.setadapter(full_roaster_adapter); return rootview; } @override public void onviewcreated(view view, @nullable bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); full_roaster_adapter = new fullroasteradapter(getactivity(), applicationglobalclass.analysts_search_arraylist); full_roaster_adapter.notifydatasetchanged(); analystslist.setadapter(full_roaster_adapter); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); toast.maketext(getactivity(), "full roaster on activity created", toast.length_short).show(); // populates list our static array full_roaster_adapter = new fullroasteradapter(getactivity(), applicationglobalclass.analysts_search_arraylist); full_roaster_adapter.notifydatasetchanged(); analystslist.setadapter(full_roaster_adapter); log.e("sizeee",string.valueof(applicationglobalclass.analysts_search_arraylist.size())); } private void initialization() { analystslist = (listview)rootview.findviewbyid(r.id.analysts_listview); analystslist.setonitemclicklistener(this); } @override public void onresume() { super.onresume(); // if (applicationglobalclass.flag) { toast.maketext(getactivity(), "full roaster on resume", toast.length_short).show(); full_roaster_adapter = new .. @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { applicationglobalclass.user_id=applicationglobalclass.analysts_search_arraylist.get(i).get(i).getid(); log.e("userid",string.valueof(applicationglobalclass.user_id)); log.e("userid2",string.valueof(applicationglobalclass.analysts_search_arraylist.get(i).get(i).getid())); //here new fragment calling fragment getactivity().getsupportfragmentmanager().begintransaction().replace(r.id.fragment_container,new flexiblespacewithimagewithviewpagertab2activity()).addtobackstack("profile1").commit(); }
you need override onbackpressed()
in activity that's hosting fragments this:
public void onbackpressed() { int = count = getfragmentmanager().getbackstackentrycount(); if (count == 0) { super.onbackpressed(); //additional code } else { getfragmentmanager().popbackstack(); }
Comments
Post a Comment