Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think what you are looking for is a TextWatcher <a href="http://developer.android.com/reference/android/text/TextWatcher.html" rel="nofollow">http://developer.android.com/reference/android/text/TextWatcher.html</a></p> <p>Assuming you have code to take care of incrementing each of your score TextViews, hook up each of the TextViews with a TextWatcher like so</p> <pre><code>One.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { int score1 = Integer.parseInt(One.getText()); int score2 = Integer.parseInt(Two.getText()); FrontNine.setText(String.valueOf(score1 + score2)); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); </code></pre> <p><strong>Edit</strong> - Apparently I misunderstood the question. To increment each of the scores, using a click handler is an acceptable approach. See code above for the complete example. Disregard the comments and code above.</p> <pre><code>private int scoreTotal1; private int scoreTotal2; private int overallTotalScore; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.score); scoreTotal1 = 0; scoreTotal2 = 0; overallTotalScore = 0; final TextView textViewtotalScore = (TextView) findViewById(R.id.TotalScore); final TextView textViewOne = (TextView) findViewById(R.id.Score1); final TextView textViewTwo = (TextView) findViewById(R.id.Score2); textViewOne.setOnClickListener(new OnClickListener() { public void onClick(View v) { scoreTotal1++; overallTotalScore = scoreTotal1 + scoreTotal2; textViewOne.setText(String.valueOf(scoreTotal1)); textViewTotalScore.setText(String.valueOf(overallTotalScore)); } }); textViewTwo.setOnClickListener(new OnClickListener() { public void onClick(View v) { scoreTotal2++; overallTotalScore = scoreTotal1 + scoreTotal2; textViewTwo.setText(String.valueOf(scoreTotal2)); textViewTotalScore.setText(String.valueOf(overallTotalScore)); } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload