title: The number of checkboxes checked
body: <p>I have 4 checkboxes and i try to show on TextView how many is checked.<br>
  I Created a variable numberOfTrue and i increase this in switch.
  Of course my app no working now, the textView still show "0"<br>
   The variable does not refresh after changing the number of clicked boxes, what i should fix now ?<br>
   I have no idea.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
  
      private int numberOfTrue = 0;
      private TextView tv1;
      private CheckBox cb1;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          CheckBox cb2,cb3,cb4;
          Button b2;
  
  
          b2 = (Button)findViewById(R.id.b2);
  
          tv1 = (TextView)findViewById(R.id.tv1);
          cb1 = (CheckBox)findViewById(R.id.cb1);
          cb1.setChecked(getFromSP("cb1"));
          cb1.setOnCheckedChangeListener(this);
          cb2 = (CheckBox)findViewById(R.id.cb2);
          cb2.setChecked(getFromSP("cb2"));
          cb2.setOnCheckedChangeListener(this);
          cb3 = (CheckBox)findViewById(R.id.cb3);
          cb3.setChecked(getFromSP("cb3"));
          cb3.setOnCheckedChangeListener(this);
          cb4 = (CheckBox)findViewById(R.id.cb4);
          cb4.setChecked(getFromSP("cb4"));
          cb4.setOnCheckedChangeListener(this);
  
  
          tv1.setText(""+numberOfTrue);
  
  
          b2.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View view) {
  
                  finish();
  
              }
          });
  
  
  
      }
  
  
      private boolean getFromSP(String key){
          SharedPreferences preferences = getApplicationContext().getSharedPreferences("PROJECT_NAME", android.content.Context.MODE_PRIVATE);
          return preferences.getBoolean(key, false);
      }
      private void saveInSp(String key,boolean value) {
          SharedPreferences preferences = getApplicationContext().getSharedPreferences("PROJECT_NAME", android.content.Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = preferences.edit();
          editor.putBoolean(key, value);
          editor.commit();
      }
  
  
  
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
          switch(buttonView.getId()){
              case R.id.cb1:
                  saveInSp("cb1",isChecked);
                  if (isChecked == true){
                      numberOfTrue++;
              }
                  break;
              case R.id.cb2:
                  saveInSp("cb2",isChecked);
                  if (isChecked == true){
                      numberOfTrue++;
                  }
                  break;
  
              case R.id.cb3:
                  saveInSp("cb3",isChecked);
                  if (isChecked == true){
                      numberOfTrue++;
                  }
                  break;
  
              case R.id.cb4:
                  saveInSp("cb4",isChecked);
                  if (isChecked == true){
                      numberOfTrue++;
                  }
                  break;
  
          }
      }
  }
  </code></pre>