I want to give each of my fragment a unique tag because they don't have id's (I'm using ViewPager) How can I do that?
public class MainActivity extends FragmentActivity {
ViewPager vp=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vp=(ViewPager)findViewById(R.id.viewpager);
FragmentManager fragmentManager=getSupportFragmentManager();
vp.setAdapter(new Adapter(fragmentManager));
}
public class Adapter extends FragmentStatePagerAdapter {
public Adapter (FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int a) {
Fragment fragment = null;
if(a==0) {
fragment = new FragmentX();
}
if(a==1) {
fragment = new FragmentY();
}
if(a==2) {
fragment = new FragmentZ();
}
return fragment;
}
@Override
public int getCount() {
return 3;
}
}
I'm a newbie on this java/android language. So just go easy on me. It'd be good if you'll answer me with code. Thank you.