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?

use ontabselectedlistener.

and in listener getposition().

something this:

tablayout.setontabselectedlistener(new tablayout.ontabselectedlistener(){     @override     public void ontabselected(tablayout.tab tab){         int position = tab.getposition();     } }); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -