public class ScraperActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scraper);
final int[] s = {0};
final TextView display = (TextView) findViewById(R.id.txtDisplay);
final TextView[] score = {(TextView) findViewById(R.id.txtScoreDisplay)};
final int[] displays = {184576, 38347, 28198, 643892, 38471872, 4783654, 1235433, 2324, 65344232, 43212, 63345543, 4321,
1554534, 65432, 324154, 7658434, 13543, 64534532, 6543563, 6543342, 7645354, 543322,
545324, 542232, 54353453, 456456, 345343453, 943242, 56454353, 1231216543, 765463532, 6453489, 43242, 54354, 5483958,
3485304, 2132151, 42345463, 23213445, 5432908, 9649372, 754938554};
final EditText input = (EditText) findViewById(R.id.txtEdit);
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
|| (actionId == EditorInfo.IME_ACTION_DONE)) {
int rando = (int) (Math.random() * displays.length);
display.setText(displays[rando]+"");//INTS - ALWAYS PARSE WITH "" OR TOSTRING()
input.setText("");
return true;
}
return false;
}
});
score[0].setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//int rando = (int) (Math.random() * displays.length);
String scr = String.valueOf(s[0]);
score[0].setText(String.format("Score %s", scr));
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
|| (actionId == EditorInfo.IME_ACTION_DONE)) &&
input.getText().toString().equals(display.getText().toString())) {
//s++;
s[0]+=1;
scr = String.valueOf(s[0]);
score[0].setText(String.format("Score%s", scr+1));
return true;
}
return false;
}
});
}
}
当输入文本等于显示的文本视图时,分数显示文本视图中的分数应增加1;但是,它仍然为零。如何才能显示增量?这是听众造成的吗?