user208562
user208562

Reputation: 21

android open specific tab fragment from click event in activity2

I am new Android and currently working on a project involving navigation between the activities within the tabbed activity(HomeActivity). I am stuck at a point where I have to navigate to a specific tab fragment, say Tab 2, from a button click event from Activity2. I have been stuck at this issue for a while now any help would be appreciated.

I have a recyclerview on tab2 which should be loaded when the tab2 opens after the click event is performed from activity2.

I have researched about it for a while but was not able to come to a solution after trying various of them. I also found a similar question here. My code fragment is also similar to the one in the link but that is an unanswered question.

I have also looked here and here.

I would appreciate if I can get some help in this matter.

Upvotes: 2

Views: 808

Answers (2)

R Besar
R Besar

Reputation: 644

Try to open this link

On link attached, i used viewPager.setCurrentItem(1,true); value 1 got from tab that opened.

To send the value 1 to my Activity, i uses sharedPreference

=======

Everytime i open the Tab, sharedPreferences always save the tab's value.

Value :

0 for Tab 1

1 for Tab 2

2 for Tab 3

Hope the solution on the link attached helps you.

Upvotes: 1

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

i have check your code your activity1 is HomePageActivity and activity2 is CreateEvents.

what your doing is: start activity2 from FloatingActionButton button click

in activity2 onClick of buttonCreateEvent you are again start activity1.

instead of start activity again just finish activity2 your problem solve if your activity start from TAB2 then when activity1 show again its show TAB2 default(at this point i assume you know life cycle methods of activity) when activity1 show again in restart method update your data using flag or static variable


please correct me if i am wrong

Upvotes: 1

Related Questions