没有意向在不同活动之间的切换工作正常 [英] Intent not working properly in switch between different activities
问题描述
我已用5 activities-calculator1.java,calculator2.java,deposit.java,calculator3.java,calculator4.java分别的应用程序,在活动1有一个切换按钮和下一个按钮,和所有其他的活动包含了下一个按钮,现在我想是时候切换按钮为pressed然后下一步按钮pressed它应该转到calculator2.java,并从calculator2.java,当我preSS下一个按钮,如果切换按钮calculator.java是上,它应该去别的deposit.java去calculator3.java,
I have made an application with 5 activities-calculator1.java,calculator2.java,deposit.java,calculator3.java,calculator4.java respectively,In activity 1 there is a toggle button and a next button,and all the other activities contains a next button,Now i want is when toggle button is pressed and next button pressed then it should goto calculator2.java,and from calculator2.java,when i press next button,if the "toggleButton" of calculator.java is "on" it should go to deposit.java else go to calculator3.java,
我的code是如下:(上单击下一步按钮):
Calculator1.java
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Calculator_1Activity.this, Calculator2.class);
intent.putExtra("toggleBtn", tg.isChecked());
startActivity(intent);
}
});
Calculator2.java
btn2.setOnClickListener(new OnClickListener() {
final boolean val= getIntent().getExtras().getBoolean("tg");
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(val==true){
Intent iq=new Intent(Calculator2.this,Deposit.class);
startActivity(iq);
}
else{
Intent ir= new Intent(Calculator2.this,Calculator_3Activity.class);
startActivity(ir);
}
}
});
Deposit.java
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent iy = new Intent(Deposit.this,Calculator_3Activity.class);
startActivity(iy);
}
});
Calculator3.java
btn2.setOnClickListener(new OnClickListener() {
// final boolean val= getIntent().getExtras().getBoolean("tg");
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1=new Intent(Calculator_3Activity.this ,Calculator_4Activity.class);
startActivity(i1);
//finish();
}
});
推荐答案
由于 Calculator1.java 的
intent.putExtra("toggleBtn", tg.isChecked());
在 Calculator2.java
final boolean val= getIntent().getExtras().getBoolean("toggleBtn");
而不是最终布尔VAL = getIntent()getExtras()getBoolean(TG);
这篇关于没有意向在不同活动之间的切换工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!