android - Wrong Fragment Picked using View Pager -
i have 3 different fragments show using view pager. have added fragment adapter follows. title shown correct on click picking wrong fragment
private void setupviewpager(viewpager viewpager) { viewpageradapter adapter = new viewpageradapter(getsupportfragmentmanager()); adapter.addfragment(new acceptsfragment(), "accepts"); adapter.addfragment(new askedfragment(), "asked"); adapter.addfragment(new helpedfragment(), "helped"); viewpager.setadapter(adapter); }
here adapter implementation.
class viewpageradapter extends fragmentpageradapter { private final list<fragment> mfragmentlist = new arraylist<>(); private final list<string> mfragmenttitlelist = new arraylist<>(); public viewpageradapter(fragmentmanager manager) { super(manager); } @override public fragment getitem(int position) { log.d("fragment clicked ",string.valueof(position)); return mfragmentlist.get(position); } @override public int getcount() { //return mfragmentlist.size(); return mfragmentist.size(); } public void addfragment(fragment fragment, string title) { mfragmentlist.add(fragment); mfragmenttitlelist.add(title); } @override public charsequence getpagetitle(int position) { return mfragmenttitlelist.get(position); } }
Comments
Post a Comment