In the onFinish method of a timer I have, I want the user to have a point added to their score if their input is equal to a random number (LoadG1). The IDE wants me to use an array and score to final. I followed its advice to remove errors but failed to achieve my goal. I spent time trying to code it in different ways (e.g: using parseInt and ==) but received the same output. I don't get what I'd expect, and instead receive "Score: [l@fea28db".
public void onFinish() {
number.setVisibility(View.GONE);
final TextView prompt = (TextView) findViewById(R.id.prompt);
prompt.setText(" Enter the number");
final EditText input = (EditText) findViewById(R.id.enterAnswer);
input.setVisibility(View.VISIBLE);
input.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode){
case KeyEvent.KEYCODE_ENTER:
Editable answer = input.getText();
input.setVisibility(View.GONE);
prompt.setVisibility(View.GONE);
if (answer.equals(loadG1)){
score[0]++;
}
return true;
default:
break;
}
}
return false;
}
});
}
Here is where I output the score:
public void onFinish() {
TextView result = (TextView) findViewById(R.id.outcome);
result.setText("Score: "+ score);
TextView prompt = (TextView) findViewById(R.id.prompt);
prompt.setVisibility(View.GONE);
}
I've also tried doing score=score+1
and score+=1
, with not difference in output. I'd greatly appreciate any help.