好吧,所以我正在制作一个 android 应用程序,基本上一切正常,期待每次“moneynum”增加 100 时更改状态文本视图的整个部分。这是我的代码:
package life.project;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class LifeActivity extends Activity {
/** Called when the activity is first created. */
ViewFlipper views;
int lifestatus=0;
TextView status;
Button main;
Button work;
TextView timer;
int moneynum=0;
int test=0;
Button GasStation;
Button Walmart;
Button Business;
TextView Moneycount;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
main=(Button) findViewById(R.id.button9);
views=(ViewFlipper) findViewById(R.id.viewFlipper1);
GasStation=(Button) findViewById(R.id.button13);
Walmart=(Button) findViewById(R.id.button23);
Business=(Button) findViewById(R.id.button33);
Moneycount=(TextView) findViewById(R.id.textView);
timer=(TextView) findViewById(R.id.textView3);
status=(TextView) findViewById(R.id.textView4);
work=(Button) findViewById(R.id.button1);
new CountDownTimer(1200000, 60000) {
public void onTick(long millisUntilFinished) {
timer.setText("Minutes remaining: " + millisUntilFinished / 60000);
}
public void onFinish() {
onPause();{
Intent timerends=new Intent("com.life.project.timesup");
startActivity(timerends);
finish();
}
}
}.start();
main.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
views.showPrevious();
}
});
work.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
views.showNext();
}
});
GasStation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
moneynum+=5;
Moneycount.setText("Money:$ "+moneynum+" .00");
if(moneynum==moneynum+100){
lifestatus+=1;
status.setText("Status: "+lifestatus);
}
}
});
Walmart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
moneynum+=10;
Moneycount.setText("Money:$ "+moneynum+" .00");
if(moneynum==moneynum+100){
lifestatus+=1;
status.setText("Status: "+lifestatus);
}
}
});
Business.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
moneynum+=20;
Moneycount.setText("Money:$ "+moneynum+" .00");
if(moneynum==moneynum+100){
lifestatus+=1;
status.setText("Status: "+lifestatus);
}
}
});
}
}
这是它不起作用的部分:
Moneycount.setText("Money:$ "+moneynum+" .00");
if(moneynum==moneynum+100){
lifestatus+=1;
status.setText("Status: "+lifestatus);
}
所以每次moneynum 增加100 我希望lifestatus 增加1 并通过其余的代码。但是当我运行程序时 if 语句没有执行,我认为这是因为我的 if 语句的参数错误..有人能弄清楚我可以使它工作吗?抱歉,如果这令人困惑。