试图评估一个简单的数学问题的正确答案。这是正确的方式去抓取输入并将其转换为一个int以便与另一个int共处吗?将edittext输入转换为整数
public void checkAnswer(){
int mm;
//answer = editText.getText().toString();
mm = Integer.parseInt(editText.getText().toString());
if (mm == correctAnswer){
score++;
scoredisplay.setText("" + score);
}
这是我如何设置correctAnswer
public void getQuestion(){
random1 = (int)(Math.random()*100);
random2 = (int)(Math.random()*10);
int i1 = Min + (int)(Math.random() * ((Max - Min) + 1));
if(i1 == 1){
question = (random1 + "+" + random2);
correctAnswer = random1 + random2;
editTextEquation.setText(question);
}
if(i1 == 2){
question = (random1 + "-" +random2);
correctAnswer = random1 - random2;
editTextEquation.setText(question);
}
if(i1 == 3){
question = random1 + "/" +random2;
correctAnswer = random1/random2;
editTextEquation.setText(question);
}
if(i1 == 4){
question = (random1 + "*" +random2);
correctAnswer = random1 * random2;
editTextEquation.setText(question);
}
else{
score--;
scoredisplay.setText("" + score);
}
按钮
@Override
public void onClick(View v){
switch(v.getId()){
case R.id.keypad_hash:
getQuestion();
checkAnswer();
break;
嘿,谢谢兄弟,我换了他们,柜台正在工作!您是否知道我如何将问题数量限制为10,然后在最后显示用户分数?假定我需要某种循环。 – Abs90 2012-03-06 19:49:43