A
A
Andrey Goroshko2018-08-16 09:58:56
Android
Andrey Goroshko, 2018-08-16 09:58:56

How to jump to a specific tab when startActivity android is called?

I have two lists of messages in the application, incoming and outgoing which are placed on two tabs, then when I select one of the messages, I go to the activity where the message is displayed. This activity has a toolbar at the bottom where the back button is located, but I can currently go to the first tab, but I need something like we opened a message from the inbox list and then when we return to the previous message list, go to the inbox list, and so - same to do with outgoing. Can somehow pass position to an activity that has a recyclerview and slidingtabs? I now have such a listener for the choice of tabs:

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
                /*String position = String.valueOf(tab.getPosition());
                Toast.makeText(SecondScreen.this,position,Toast.LENGTH_LONG).show();*/
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

I'm thinking where to pass position? after all, in fact, if viewPager.setCurrentItem(tab.getPosition());
I insert into this piece of code, then I will only select the tab that comes with the intent, and on my own when the application starts, it will not be known which tab to select. Perhaps I explained very confusingly, but I hope for help and advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Chvarkov, 2018-08-16
@Drew20

when you call an activity with tabs from the screen with a message - pass the position to it via intent.putExtra("position", index);
and inside the activity - getIntent.getIntExtra("position", defIndex); And instead of defIndex - the index of the tab to open if nothing came (for example, when you get to the screen with tabs from other places)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question