好吧所以即时创建一个Android应用程序,基本上一切都工作正常,期待整个部分关于改变状态textview每次“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语句的参数错误。有人知道我可以使这个工作吗?抱歉,如果这令人困惑。
答案 0 :(得分:0)
public .... LifeActivity
{
int moneySum = 100;
....
....
}
public void moneyCount()
{
if(moneynum>=moneySum) // Morethan incase your using looking for when moneynum passes 100 mark not when it equal exactly 100
{
lifestatus+=1;
status.setText("Status: "+lifestatus);
moneySum+=100;
}
}
public void onClick(View v) {
// TODO Auto-generated method stub
moneynum+=20;
Moneycount.setText("Money:$ "+moneynum+" .00");
moneyCount();