android - How do I set my RadioButtons to increase the score only once even after being clicked multiple times? -


my issue have set scoring system each of radio buttons in radio group when click radio button multiple times or change answer score keeps on increasing. how set score increases once when radio button clicked , when answer changed show score of new option selected?

public class mainactivity extends appcompatactivity { int score = 0; public textview tv;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     tv = (textview)findviewbyid(r.id.textview); } public void onradiobuttonclicked(view view) {     //is current radio button checked?     boolean checked = ((radiobutton) view).ischecked();      //now check radio button selected     //android switch statement     switch (view.getid()) {         case r.id.radiobutton:             if (checked)                 score += 1;             break;         case r.id.radiobutton2:             if (checked)                 score += 1;             break;         case r.id.radiobutton3:             if (checked)                 score += 3;             break;         case r.id.radiobutton4:             if (checked)                 score += 5;             break;     }     updatescore(score); }   public void updatescore(int score) {     tv.settext(" " + score); } }     

i not sure if understand problem completely. if want score change according options, can either of following -

  1. make score variable local variable. or
  2. don't add score of option previous score i.e. replace += = everywhere i.e.

    score = 1; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -