0
我有三個屏幕(3片段和viewPager)的應用程序,現在我想發送例如字符串從活動到FragmentA,但我不知道如何。發送數據從活動片段與ViewPager
這是我的活動類尋呼機適配器
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;
}
你可以在這裏的答案中使用解決方案:http://stackoverflow.com/questions/36503779/refresh-data-in-viewpager-fragment –