Intent To Open A Specific Tab Of Tabbed Activity
I have a tabbed activity with 5 tabs. Each tab has only one Imageview. On a previous page I have 5 buttons and I want to create an interface such that each button starts the tabbed
Solution 1:
You can pass the tab id you want to open as an extra to the Intent
you are creating. Then in the tabbed Activity
, assuming you are using TabLayout
, you can do something like this -
TabLayouttabLayout= (TabLayout) findViewById(R.id.tabs);
TabLayout.Tabtab= tabLayout.getTabAt(getIntent().getStringExtra("selected_index"));
tab.select();
Solution 2:
Try This
First activity
int page = 2; Intent intent = newIntent(FirstActivity.this,TabActivityClass.class); intent.putExtra("One", page);// One is your argument startActivity(intent);
2.In oncreate method of TabActivity class
int defaultValue = 0; int page = getIntent().getIntExtra("One", defaultValue); viewPager.setCurrentItem(page);
Post a Comment for "Intent To Open A Specific Tab Of Tabbed Activity"