android - Using Swipe view in drawer navigation -
i'm made navigation drawer
, listview
have complete , decided main content right of it. had , i'm gonna replace swipe view. i can't find swipe-view-in-drawer-navigation tutorial anywhere. seen on bland activity extends fragmentactivity ive extends else due navigation actionbaractivity
. don't know now.
please give me hint
so need tutorial explaining viewpager implementation
here 1 tutorial
its similar listview
, adapter
implementation. going have view pager in layout file have listview.
<android.support.v4.view.viewpager android:id="@+id/my_viewpager" android:layout_width="match_parent" android:layout_height="match_parent"/>
then need adapter , views fill in adapter. fragmentpageradapter
trick you. how implement this
list<viewpageradapter.fragmenttabitem> fragmentlist = new arraylist<>(); fragmentlist.add(new viewpageradapter.fragmenttabitem(myfragmentone.newinstance(), getstring(r.string.one))); fragmentlist.add(new viewpageradapter.fragmenttabitem(myfragmenttwo.newinstance(), getstring(r.string.two))); viewpageradapter adapter = new viewpageradapter(getchildfragmentmanager() , fragmentlist); mviewpager.setadapter(adapter);
here generic adapter implementation
public class viewpageradapter extends fragmentpageradapter { list<fragmenttabitem> mfragmenttabitems; public viewpageradapter(fragmentmanager fm, list<fragmenttabitem> fragmenttabitems) { super(fm); mfragmenttabitems = fragmenttabitems; } @override public fragment getitem(int position) { return mfragmenttabitems.get(position % mfragmenttabitems.size()).getfragment(); } @override public int getcount() { if(mfragmenttabitems != null) return mfragmenttabitems.size(); else return 0; } @override public charsequence getpagetitle(int position) { return mfragmenttabitems.get(position % mfragmenttabitems.size()).gettitle(); } public static class fragmenttabitem { @getter @setter fragment fragment; @getter @setter string title; public fragmenttabitem(fragment fragment, string title) { this.fragment = fragment; this.title = title; } }}
Comments
Post a Comment