I want to update the score in the activity without refreshing the activity.
I have the code 1 textView and 3 buttons.
Android: & Lt; Button Android: id = "@ + id / q2" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> & Lt; Button Android: id = "@ + id / q3" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> Subdate score activity:
Last text view TxtScore = (TextView) findViewById (R.id.score); Last int UpdateScore = i.getExtras (). GetInt ("UpdateScore"); Find Last button q1 = (button) ViewById (R.id.q1); Find the last button q2 = (button) VVBIID (RIDQ2); Find the last button q3 = (button) VVBIID (RWQ3); Q1.setOnClickListener (new OnClickListener) {public void onClick (see v) {if (answer.equals ("true") {TxtScore.setText (integer.stosting (updatescore + 1))} and {TxtScore.setText (integer .toString (UpdateScore - 1));}}}; q2.setOnClickListener (New OnClickListener) {public void onClick (see v) {if (answer.equals ("true") {TxtScore.setText (Integer.toString ( UpdateScore + 1));} Other {TxtScore.setText (Integer.toString (UpdateScore - 1)}}}}); q3.setOnClickListener (New OnClickListener) {public void onClick (see v) {if (answer.equals ("Right") {TxtScore.setText (integer. Stosting (score + 1)); and {textteacore .set text (integer.tostosting (updatescoin-1))}}}} ); The above code, what I want, is not working as such, when personal updates are working in the TextView on onClick .. But I automatically update the score Example bellow
Examples of example moving from past: Int score = 10;
- When pressing q1 is "true" Score 11 will be updated;
- When q2 "wrong" the score will be updated to 10
- when q3 "incorrect" the score 9 will be updated
something like that.
But I'm really screwing on updates automatically.
Thanks & amp; Regards,
Only God knows what this code is all about, errors are too big.
Do this in any case:
change final integer score = 0; to int score = 0; every int x = score + 1; to score = score + 1; to change every int x = score - 1; to score = score - 1; UpdateScore.setText (integer.txtin (x)) for each ; to UpdateScore.setText (Score + ""); ...
Wait, do you have that code on all onCreate () ? If so, transfer all variable declarations out of it, make them class / activity level. EDIT ====
Increases the MainActivity activity of the public class {Private TextView TxtScore = Zero; Private button q1 = null; Private button q2 = null; Private button q3 = faucet; Private int score = 10; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); ... TxtScore = (TextView) Find ViewById (R.id.score); Find Q1 = (button) VVBIID (RIDQ1); Q2 = Find (VBID) (RIDQ2); Q3 = (button) Find VibibIID (RWQ3); / * And your on-the-line listener, with the changes I have made here * / Q1.setOnClickListener (new OnClickListener) {public void onClick (see v) {if.equals ("true") {TxtScore.setText (++ score + "");} else {TxtScore.setText (- -score + "");}}}) ....}
No comments:
Post a Comment