You can pass a variable to
ShowPage
, and use
setCurrentItem
to set the viewPager index.
In MainActivity
case 0:
Intent intent = new Intent(MainActivity.this, ShowPage.class);
intent.putExtra("position",0);
startActivity(intent);
break;
case 1:
Intent intent1 = new Intent(MainActivity.this, ShowPage.class);
intent1.putExtra("position",5);
startActivity(intent1);
break;
In ShowPage
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
int data = intent.getIntExtra("position",0);
viewPager = findViewById(R.id.viewPager);
if (viewPager != null){
viewPagerAdapter adapter = new viewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(data);
}