0% found this document useful (0 votes)
15 views

New Text Document

The document sets up a ViewPager with two fragments and assigns titles to each tab using FragmentPagerAdapter.

Uploaded by

Padmaja Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

New Text Document

The document sets up a ViewPager with two fragments and assigns titles to each tab using FragmentPagerAdapter.

Uploaded by

Padmaja Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

setContentView(R.layout.

activity_welcome);
viewPager=(ViewPager)findViewById(R.id.pager);
FragmentManager fragmentManager=getSupportFragmentManager();
viewPager.setAdapter(new MyAdapter(fragmentManager));
}
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
Fragment fragment=null;
@Override
public Fragment getItem(int position) {
if(position==0)
{
fragment=new FragmentA();
}
if(position==1)
{
fragment=new Fragment_B();
}
return fragment;
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
if(position==0)
{
return "tab1";
}
if(position==1)
{
return "tab2";
}
return "hi";
}
}

You might also like