title: How to sum checkboxes value in android?
body: <p>I have a problem in java.</p>
  
  <pre><code>package apa.y;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.CheckBox;
  import android.widget.TextView;
  
  
  
  public class myprice extends Activity  {
      /** Called when the activity is first created. */
  
  
      CheckBox book,pencil;
      TextView total;
      int sum=0;
  
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.mymain);
      pencil = (CheckBox) findViewById(R.id.pencil);
      book = (CheckBox) findViewById(R.id.book);
      total = (TextView) findViewById(R.id.total);
  
      }
  
      public void onClick(View v) {
  
          sum = 0;
          if (pencil.isChecked()) {sum += 10;}else{sum +=0;}
          if (book.isChecked())   {sum += 5;}else{sum +=0;}
  
          total.setText("Total: "+sum);
  
      }
  }
  </code></pre>
  
  <p>If book and pencil are checkbox and 1 textview, how to sum it? My existing code didn't work.</p>