Increment TextView with button click

后端 未结 2 425
悲&欢浪女
悲&欢浪女 2020-12-22 07:24

thanks for the help but I\'m still struggling. I did this:

Button in xml:

2条回答
  •  清酒与你
    2020-12-22 08:17

    In your class create:

           int score = 0;
    

    And then;

           button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // score operation like score += increment_value;
                    t1.setText(""+score);
                }
            });
    

    If you need to "save" the score ocne you quit the application, you need to use SharedPreferences to show/update the value.

提交回复
热议问题