I'm quite new to Android so please don't shoot me for asking a dumb question. I've already checked 'Stackoverflow' and many other sites but can't seem to find the right answer...
I'm creating a simple math app to help my daughter with her math. While I try to create two random numbers in, let's say the multiplication table of 1, they always start with the two same numbers (8x7). After I click my submit button though, I get the 'right' numbers which means that the first number is '1' and the second number is a number between '0' and '11'.
Any help is appreciated. Thanks!
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class Vermenigvuldig extends Activity implements OnClickListener {
TextView firstNumber;
TextView secondNumber;
TextView times_sign, equals_sign, ok;
EditText answer;
Button submit;
int solution;
// int firstNumberB, secondNumberB;
ImageView thumbs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vermenigvuldig);
firstNumber = (TextView) findViewById(R.id.tv_fnum);
secondNumber = (TextView) findViewById(R.id.tv_snum);
times_sign = (TextView) findViewById(R.id.tv_x);
answer = (EditText) findViewById(R.id.et_answer);
submit = (Button) findViewById(R.id.b_submit);
submit.setOnClickListener(this);
thumbs = (ImageView) findViewById(R.id.iv_thumbs);
}
@Override
public void onClick(View v) {
Random myRandom = new Random();
switch (v.getId()) {
case R.id.b_submit:
int test1 = Integer.parseInt(firstNumber.getText().toString());
int test2 = Integer.parseInt(secondNumber.getText().toString());
solution = test1 * test2;
firstNumber.setText(String.valueOf(myRandom.nextInt(10)));
secondNumber.setText(String.valueOf(myRandom.nextInt(10)));
int outcome = Integer.parseInt(answer.getText().toString());
if (outcome == solution) {
thumbs.setImageResource(R.drawable.thumbsup);
} else {
thumbs.setImageResource(R.drawable.thumbsdown);
}
answer.setText("");
break;
}
}
}