title: How to insert data in database using checkboxes?
body: <p>I'm trying to insert data into the database using check boxes, but I'm not sure how to go about doing it.If the User selects a check box and click the update button, it will be inserted into the database.</p>
  
  <p>Here's my code.</p>
  
  <p><em>CXATest1Activity</em></p>
  
  <pre><code>public class CXATest1Activity extends Activity {
  /** Called when the activity is first created. */
  DBCXAAdapter db = new DBCXAAdapter(this);
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //set up main content view
      setContentView(R.layout.main);
  
      Button button1main = (Button) findViewById(R.id.Button01main);
  
      button1main.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
  
           db.open();
  
              EditText editTextName = (EditText)findViewById(R.id.EditTextName);
              String NameValue = editTextName.getText().toString();
  
              EditText editTextAge = (EditText)findViewById(R.id.EditTextAge);
              String AgeValue = editTextAge.getText().toString();
  
              EditText editTextMedicalBackgroundBody = (EditText)findViewById(R.id.EditTextMedicalBackgroundBody);
              String MedicalBackgroundBodyValue = editTextMedicalBackgroundBody.getText().toString();
  
              Spinner editTextSpinnerGenderType = (Spinner)findViewById(R.id.SpinnerGenderType);
              String GenderTypeValue = editTextSpinnerGenderType.getSelectedItem().toString();
  
              Spinner editTextSpinnerMedicalBackgroundSelectType = (Spinner)findViewById(R.id.SpinnerMedicalBackgroundSelectType);
              String MedicalBackgroundSelectTypeValue = editTextSpinnerMedicalBackgroundSelectType.getSelectedItem().toString();
  
              CheckBox editTextCheckboxMedicalBackgroundCancer = (CheckBox)findViewById(R.id.checkBoxCancer);
              String MedicalBackgroundCancerValue = editTextCheckboxMedicalBackgroundCancer.getText().toString();
  
              editTextCheckboxMedicalBackgroundCancer.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
  
              long id;
              id = db.insertUserprofile(NameValue, AgeValue, MedicalBackgroundBodyValue, GenderTypeValue, MedicalBackgroundSelectTypeValue, MedicalBackgroundCancerValue);
  
              db.close(); 
  
  
                  //set up dialog
                  final Dialog dialog = new Dialog(CXATest1Activity.this);
                  dialog.setContentView(R.layout.maindialog);
                  dialog.setTitle("Congrats");
                  dialog.setCancelable(true);
                  //there are a lot of settings, for dialog, check them all out!
  
                  //set up text
                  TextView text = (TextView) dialog.findViewById(R.id.TextView01);
                  text.setText(R.string.lots_of_text);
  
                  //set up image view
                  ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
                  img.setImageResource(R.drawable.updated_icon_new1);
  
                  //set up button
                  Button button = (Button) dialog.findViewById(R.id.Button01);
                  button.setOnClickListener(new OnClickListener() {
                  public void onClick(View v) {
  
                          dialog.dismiss();
                      }
                  });
                  //now that the dialog is set up, it's time to show it    
                  dialog.show();
              }
  </code></pre>
  
  <p><em>DBCXAAdapter</em></p>
  
  <pre><code>//---insert a userprofile into the database---
  public long insertUserprofile(String name, String age, String medicalbackground, String spinnergender, String spinnermedicalbackground, String checkboxmedicalbackgroundcancer) 
  {
      ContentValues initialValues = new ContentValues();
      initialValues.put(KEY_NAME, name);
      initialValues.put(KEY_AGE, age);
      initialValues.put(KEY_MEDICALBACKGROUND, medicalbackground);
      initialValues.put(KEY_SPINNERGENDER, spinnergender);
      initialValues.put(KEY_SPINNERMEDICALBACKGROUND, spinnermedicalbackground);
      initialValues.put(KEY_CHECKBOXMEDICALBACKGROUNDCANCER, checkboxmedicalbackgroundcancer);
    return db.insert(DATABASE_TABLE, null, initialValues);
  }
  </code></pre>
  
  <p>Thank in advance.</p>