It turns out that I have this class in which I keep the information of, among other things, 4 Checkboxes in my SQLite Database, but it does not matter if the Checkboxes are selected or not, I always load "No" in my database. data.
To better understand what I mean, I share the class where I did the aforementioned:
public class Dia extends AppCompatActivity {
private String day, reserva;
EditText etComentario;
Button bnGuardarC, bnSalirC;
TextView tvNumDia;
CheckBox cbBaniar, cbPasear, cbCortar, cbJugar;
RadioGroup rgTurno;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dia);
reserva = getIntent().getStringExtra("reserva");
rgTurno = findViewById(R.id.rgTurno);
bnGuardarC = findViewById(R.id.bnGuardarC);
bnSalirC = findViewById(R.id.bnSalirC);
tvNumDia = findViewById(R.id.tvNumeroDia);
cbBaniar = findViewById(R.id.cbBaniar);
cbPasear = findViewById(R.id.cbPasear);
cbCortar = findViewById(R.id.cbCortar);
cbJugar = findViewById(R.id.cbJugar);
etComentario = findViewById(R.id.etComentario);
day = getIntent().getStringExtra("numdia");
final String baniar, pasear, cortar, jugar;
if(cbBaniar.isChecked()){
baniar="Si";
}else{
baniar="No";
}
if(cbPasear.isChecked()){
pasear="Si";
}else{
pasear="No";
}
if(cbCortar.isChecked()){
cortar="Si";
}else{
cortar="No";
}
if(cbJugar.isChecked()){
jugar="Si";
}else{
jugar="No";
}
TextView tvDia = findViewById(R.id.tvNumeroDia);
tvDia.setText(day);
final BaseDeDatos tablaCuidados = new BaseDeDatos(getApplicationContext());
bnGuardarC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tablaCuidados.insertarCuidado(null, "#1111", day, rgTurno.getCheckedRadioButtonId(), baniar, pasear,
cortar, jugar, etComentario.getText().toString());
Toast.makeText(getApplicationContext(), "¡Cuidado guardado con éxito!", Toast.LENGTH_SHORT).show();
}
});
}
}
As you can see, I check the Checkboxes for an If, and if .isChecked == true, I should keep "Yes" in its variable, otherwise I should keep "No". The app runs rather well, only when I go to see what was saved in my database, the fields in the table that refer to the Checkbox are all loaded in "No", that is, if the .isChecked does not It was working. Maybe I'm not using it the right way, could you help me?
I leave a screenshot below with the results of my database and checkboxes fields marked in yellow:
Thank you!