从EditText比较输入整数时遇到问题。我无法找到它有什么问题。请帮帮我。这是下面的代码。EditText整数比较
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.problem2);
textIn = (EditText) findViewById(R.id.probText);
Button ans3 = (Button) findViewById(R.id.answer3);
ans3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String probString = textIn.getText().toString();
Integer probInt = Integer.parseInt(probString);
Integer prob = 31;
if (probInt.equals(prob)) {
Toast toast = Toast.makeText(answer3.this,"CORRECT!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
startActivity(new Intent("com.sample.androidsample.ANSWER4") );
} else {
Toast toast = Toast.makeText(answer3.this,"Wrong answer! Try again.",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
}
});
}
您是否尝试过(probInt ==概率)? – 2012-08-16 00:48:33
可以哟把Log.i(“@@@”,probString);在字符串之后probString = textIn.getText()。toString();并检查logcat中的输出是什么? – Hesam 2012-08-16 00:49:41
try(probInt == prob)它总是返回else语句 – 2012-08-16 00:51:50