我有三个屏幕(3个片段和viewPager)的应用程序,现在我想发送例如String从Activity到FragmentA,但我不知道如何。
这是我的具有寻呼机适配器的Activity类
public class MainActivity extends FragmentActivity {
ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager= (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
}
}
类MyAdapter扩展了FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
Fragment fragment=null;
if(arg0==0){
fragment=new FragmentA();
}
if(arg0==1){
fragment=new FragmentB();
}
if(arg0==2){
fragment=new FragmentC();
}
return fragment;
}
@Override
public int getCount() {
return 3;
}