java - How to get current selected tab index in TabLayout? -
when use actionbar tabs, use code.
private int getcurrenttabindex() { actionbar actionbar = activity.getsupportactionbar(); actionbar.tab selectedtab = actionbar.getselectedtab(); if(selectedtab == null){ return 0; } return selectedtab.getposition(); }
but how can using tablayout?
and in listener getposition()
.
something this:
tablayout.setontabselectedlistener(new tablayout.ontabselectedlistener(){ @override public void ontabselected(tablayout.tab tab){ int position = tab.getposition(); } });
Comments
Post a Comment