以下是两项活动:
Test_Result.java
Intent intent = new Intent();
intent.putExtra("flag","data");
intent.setClass(Test_Result.this, MainActivity.class);
startActivity(intent);
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mainPager=(MyViewPager) findViewById(R.id.vPager);
radioGroup=(RadioGroup) findViewById(R.id.bottom_bar);
radioGroup.setOnCheckedChangeListener(this);
Intent intent = getIntent();
flag = intent.getStringExtra("flag");
if (flag == null){
initViews();
radioGroup.getChildAt(2).performClick();
}
else {
if (flag.equals("test")) {
initViews();
radioGroup.getChildAt(0).performClick();
}
if (flag.equals("data")) {
initViews();
radioGroup.getChildAt(1).performClick();
}
if (flag.equals("info")) {
initViews();
radioGroup.getChildAt(2).performClick();
}
}
}
private void initViews(){
fm=getSupportFragmentManager();
fragments=new ArrayList<Fragment>();
testFragment=TestFragment.getInstance();
dataFragment= DataFragment.getInstance();
informationFragment=InformationFragment.getInstance();
fragments.add(testFragment);
fragments.add(dataFragment);
fragments.add(informationFragment);
mainPager.setAdapter(new MainPageAdpter(fm));
}
当它跳转时,除了radioGroup之外的3个片段中没有视图。 但是当我打开应用程序时,MainActivity中有三个片段。 为什么?两周前我刚刚开始学习Android,我是无辜的,请帮助我。