Java android Fragment tabs (changed fragment only when swipe) don't work click on tabs name -
i have activity in have 2 fragments , when swipe on tabs fragments change , when click on tabs name apk doesn't change view. stay on same fragments.
this activity :
public class objectlistactivity extends appcompatactivity { private toolbar toolbar; private tablayout tablayout; private viewpager viewpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_object_list2); toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); hidesoftkeyboard(); android.support.v7.app.actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(android.app.actionbar.navigation_mode_standard); actionbar.settitle(""); getsupportactionbar().setdisplayhomeasupenabled(false); viewpager = (viewpager) findviewbyid(r.id.viewpager); setupviewpager(viewpager); tablayout = (tablayout) findviewbyid(r.id.tabs); tablayout.setupwithviewpager(viewpager); } public void hidesoftkeyboard() { if(getcurrentfocus()!=null) { inputmethodmanager inputmethodmanager = (inputmethodmanager) getsystemservice(input_method_service); inputmethodmanager.hidesoftinputfromwindow(getcurrentfocus().getwindowtoken(), 0); } } private void setupviewpager(viewpager viewpager) { viewpageradapter adapter = new viewpageradapter(getsupportfragmentmanager()); adapter.addfragment(new fragmentallobjectactivity(), getstring(r.string.all)); adapter.addfragment(new fragmentgroupobjectsactivity(), getstring(r.string.group)); viewpager.setadapter(adapter); } 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) { return mfragmentlist.get(position); } @override public int getcount() { return mfragmentlist.size(); } public void addfragment(fragment fragment, string title) { mfragmentlist.add(fragment); mfragmenttitlelist.add(title); } @override public charsequence getpagetitle(int position) { return mfragmenttitlelist.get(position); } } }
and xml layout :
<android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:background="@drawable/logowanie_tlo" android:layout_height="match_parent"> <!--<android.support.design.widget.appbarlayout--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:theme="@style/themeoverlay.appcompat.dark.actionbar">--> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:layout_scrollflags="scroll|enteralways" /> <android.support.design.widget.tablayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabmode="fixed" app:tabgravity="fill"/> <!--</android.support.design.widget.appbarlayout>--> <android.support.v4.view.viewpager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.coordinatorlayout>
Comments
Post a Comment