Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a specific tab when opening a Sliding Tab Layout activity?

I tried this tutorial and it works great, but now I would like to know if it is possible, when opening the application, to go directly to a specific tab and not the first one (at left) by default ?

Ex : I would like the application to open directly on "events" tab :

enter image description here

I searched into the code, but didn't find anything relevant.

Thanks folks

EDIT : Here is the way : Just add pager.setCurrentItem(1); in your MainActivity (the tabs container).

like image 992
Rob Avatar asked Feb 04 '15 13:02

Rob


People also ask

How do you make a tabbed activity?

Let's Get Started 👉 Create a new project “Android TabLayout” or “Android Tabs Layout“. 👉 Select targeted Android device. 👉 Add an activity to mobile => Select Empty Activity. 👉 Customize the activity.


1 Answers

ViewPager is most often used in conjunction with Fragment, which is a convenient way to supply and manage the lifecycle of each page.

You can use setCurrentItem // Set the currently selected page.

Set the currently selected page. If the ViewPager has already been through its first layout with its current adapter there will be a smooth animated transition between the current item and the specified item.

Finally,

Your_View_Pager_Obj.setCurrentItem(1); // call into onCreate(Bundle savedInstanceState) 
like image 110
IntelliJ Amiya Avatar answered Oct 27 '22 01:10

IntelliJ Amiya