title: how to get a boolean value of checkbox whether it is checked or unchecked- android studio?
body: <p>I am using <code>checkbox</code> to register a faculty if the <code>checkbox</code> is checked, else- by default, student is registered <code>onClick</code>. The checkbox value is always checked using the <code>checkbox.isChecked()</code>, how do i change it so that it will get the status of the checked/unchecked in <code>boolean</code> form. 
  i need it in <code>boolean</code> since i have used a <code>boolean</code> parameter in the Database Helper class in the <code>insertData()</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/dCMFZ.png" alt="The register activity page (image)"></p>
  
  <p>DatabaseHelper.java</p>
  
  <pre><code>import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  
  public class DatabaseHelper extends SQLiteOpenHelper{
  
  public static final String DATABASE_NAME ="Register.db";
  public static final String TABLE_STUDENT ="Register_student";
  public static final String TABLE_FACULTY ="Register_faculty";
  public static final String TABLE_ATTENDANCE ="Attendance_edit";
  public static final String COL_1 ="Name";
  public static final String COL_2 ="Username";
  public static final String COL_3 ="Password";
  public static final String COL_4 ="Roll No";
  public static final String COL_5 ="Course Code";
  public static final String COL_6 ="Batch";
  private static final String CREATE_TABLE_STUDENT = "CREATE TABLE "
          + TABLE_STUDENT + "(" +  COL_1
          + " TEXT," + COL_2 + "TEXT," + COL_3
          + " TEXT" + ")";
  
  private static final String CREATE_TABLE_FACULTY = "CREATE TABLE "
          + TABLE_FACULTY + "(" +  COL_1
          + " TEXT," + COL_2 + "TEXT," + COL_3
          + " TEXT" + ")";
  
  private static final String CREATE_TABLE_ATTENDANCE = "CREATE TABLE "
          + TABLE_ATTENDANCE + "(" +  COL_4
          + " TEXT," + COL_5 + "TEXT," + COL_6
          + " TEXT" + ")";
  
  public DatabaseHelper(Context context) {
      super(context, DATABASE_NAME, null, 1);
  
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
  
      db.execSQL(CREATE_TABLE_STUDENT);
      db.execSQL(CREATE_TABLE_FACULTY);
      db.execSQL(CREATE_TABLE_ATTENDANCE);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDENT);
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_FACULTY);
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_ATTENDANCE);
  
      onCreate(db);
  }
  
  public boolean insertData(String name, String username, String password,   
  boolean checked)
  {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues contentValues = new ContentValues();
      contentValues.put(COL_1, name);
      contentValues.put(COL_2, username);
      contentValues.put(COL_3, password);
  
      if(!checked) {
        long result=  db.insert(TABLE_STUDENT, null, contentValues);
          if(result == -1)
          {
              return false;
          }
          else
          {
              return true;
          }
      }
     else
  
      { long result = db.insert(TABLE_FACULTY,null,contentValues);
          if(result == -1)
          {
              return false;
          }
          else
          {
              return true;
          }
      }
  
  }
  
  public boolean newinsertData(String rollno, String course, String batch)
  {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues contentValues = new ContentValues();
      contentValues.put(COL_4, rollno);
      contentValues.put(COL_5, course);
      contentValues.put(COL_6, batch);
      db.insert(TABLE_ATTENDANCE, null, contentValues);
      long result = db.insert(TABLE_FACULTY,null,contentValues);
      if(result == -1)
      {
          return false;
      }
      else
      {
          return true;
      }
  
  }
  
  public Cursor getAllData()
  {
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor res = db.rawQuery("select * from" + TABLE_ATTENDANCE, null);
  
  
  return res;
  
  }
  
  public Cursor ViewData() {
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor result = db.rawQuery("select * from" + TABLE_FACULTY, null);
      return result;
  }
  public Cursor getData() {
      SQLiteDatabase db = this.getWritableDatabase();
  
      Cursor results = db.rawQuery("select * from" + TABLE_STUDENT, null);
      return results;
  }
  
  }
  </code></pre>
  
  <p>The problem is when i use the <code>insertData</code> method in the register.java class.</p>
  
  <p>register.java</p>
  
  <pre><code>import android.app.AlertDialog;
  import android.database.Cursor;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.Button;
  import android.view.View;
  import android.widget.CheckBox;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class register extends AppCompatActivity {
  Button register, viewdata;
  CheckBox faculty;
  EditText editName, editUName, editPass;
  DatabaseHelper myDB;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_register);
      myDB = new DatabaseHelper(this);
      editName = (EditText) findViewById(R.id.editText3);
      editUName = (EditText) findViewById(R.id.editText4);
      editPass = (EditText) findViewById(R.id.editText5);
      faculty = (CheckBox) findViewById(R.id.checkBox38);
      register = (Button) findViewById(R.id.button2);
      viewdata = (Button) findViewById(R.id.button13);
     register();
      viewdata();
  }
  public void register() {
      register.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              boolean isInserted =    
  myDB.insertData(editName.getText().toString(),
                      editUName.getText().toString(),        
  editPass.getText().toString(), faculty.isChecked());
  
  
              if (isInserted == true) {
                  Toast.makeText(getApplicationContext(), "Data added,      
  registered!", Toast.LENGTH_SHORT).show();
              } else {
                  Toast.makeText(getApplicationContext(), "Data not added",           
  Toast.LENGTH_SHORT).show();
              }
          }
      });
      }
  
  
          public void viewdata() {
              viewdata.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      if (faculty.isChecked()) {
                          Cursor result = myDB.ViewData();
  
                          if (result.getCount() == 0) {
                              showMessage("Error!", "nothing found");
  
                              return;
                          }
  
                          StringBuffer buffer = new StringBuffer();
  
                          while (result.moveToNext()) {
                              buffer.append("Name: " + result.getString(0) + 
   "\n");
                              buffer.append("Username: " + result.getString(1)  
   + "\n");
                              buffer.append("Password: " + result.getString(2)
   + "\n\n");
                          }
                          showMessage("Data", buffer.toString());
                      }
                      else {
                          Cursor results = myDB.getData();
  
                          if (results.getCount() == 0) {
                              showMessage("Error!", "nothing found");
  
                              return;
                          }
  
                          StringBuffer buffer = new StringBuffer();
  
                          while (results.moveToNext()) {
                              buffer.append("Name: " + results.getString(0) +     
   "\n");
                              buffer.append("Username: " +  
   results.getString(1) + "\n");
                              buffer.append("Password: " + 
   results.getString(2) + "\n\n");
                          }
                          showMessage("Data", buffer.toString());
                      }
  
                  }
              });
          }
  public void showMessage (String title, String Message)
  {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setCancelable(true);
      builder.setTitle(title);
      builder.setMessage(Message);
      builder.show();
  }
  }
  </code></pre>