如何在单击上一个活动中的按钮时更改新活动中的微调器 我在activity1中有2个按钮 如果我点击第一个按钮,它应该用spinner s1打开activity2 如果单击秒,则旋转器应为s2
这是代码,我只能打开新活动
switch (v.getId()) {
case R.id.release:
Intent wg = new Intent("com.pttest.com.pockettankstips.release");
startActivity(wg);
break;
case R.id.alpha:
Intent cg = new Intent("com.pttest.com.pockettankstips.release");
startActivity(cg);
break;
default:
break;
}}
答案 0 :(得分:0)
编写FirstActivity onCreate
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent("com.pttest.com.pockettankstips.release");
Bundle b = new Bundle();
b.putInt("index",1);
intent.putExtras(b);
startActivity(intent);
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent("com.pttest.com.pockettankstips.release");
Bundle b = new Bundle();
b.putInt("index",2);
intent.putExtras(b);
startActivity(intent);
}
});
编写SecondActivity(com.pttest.com.pockettankstips.release
)onCreate
Bundle b = getIntent().getExtras();
int index = b.getInt("index");
if(index == 1){
//s1 spinner
//example: show spinner1
//spinner1.setVisibility(View.VISIBLE);
//spinner2.setVisibility(View.GONE);
}else{
//s2 spinner
//example: show spinner2
//spinner1.setVisibility(View.GONE);
//spinner2.setVisibility(View.VISIBLE);
}