android - Increment TextView with button click -


Thanks for the help, but I am still struggling. I did this:

Button in XML:

  & amp; Android: layout_centerHorizontal = "true" android: layout_marginTop = "43dp" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Background = "@ Android: Color / White" Android: onClick = "incrementScore" Android: text = "@ string / player" />   

Main code (in the end):

Where do I get this code especially when I press the app crash button should keep?

  context reference; TextView TV; Button incremental; Public zero growth score (bundle saved instenstate) {super.onCreate (SavedInstanceState); SetContentView (R.layout.fragment_home); TV = (TextView) FindViewById (R.id.textView1); Incrementer = (button) findViewById (R.id.button1); Context = this; . Incrementer.setOnClickListener (New View.OnClickListener) {@Override Public Zero onClick (see v) {string present_value_string = tv.getText () toString (); Integer present_value_int = Integer.parseInt (present_value_string); present_value_int ++; tv.setText (String.valueOf (present_value_int));}}); }    

Build in your class:

  int Score = 0;   

And then;

  button.setOnClickListener (New OnClickListener () {@Override Public Zero onClick (see v) {// Scores like score operation operation = = increment_value; t1.setText ("" + score); }});   

If you need to "save" scores, then you have left the application, you need to share to show / update the stock.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -