我想在两个活动之间发送数据,并根据数据显示一个视图(我有一个 frameLayout,并基于该数据提交一个用于填充 frameLayout 的片段)。我写了这段代码,但我认为它不是在两个活动之间传输数据!因为总是大小写 0!正在执行
问题是什么??
溅:
private OnClickListener onClickListener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("circuleProduct", "clicked");
Intent intent;
switch(v.getId()){
case R.id.btnCircleProduct:
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
intent.putExtra("value",1 );
break;
case R.id.btnCircleIntroduce:
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
intent.putExtra("value", 2);
break;
case R.id.btnCircleContact:
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
intent.putExtra("value", 3);
break;
case R.id.btnCircleMore:
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
intent.putExtra("value", 4);
break;
}
}
};
活动:
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int value=0;
Intent intent=getIntent();
value=intent.getIntExtra("value", 0);
switch(value){
case 0:
ft.add(R.id.frameLayout, new Introduce());
ft.commit();
break;
case 1:
ft.add(R.id.frameLayout, new Product());
ft.commit();
case 3:
ft.add(R.id.frameLayout, new Contact());
ft.commit();
case 4:
ft.add(R.id.frameLayout, new More());
ft.commit();
break;
}
}
}