I need to store a boolean data in an integer, since I had seen that the SQLite android databases do not allow booleans. But I do not know how, it is to check if a RadioButton is marked, or vulgarly "checkeado". I tried this:
int r1 = radio1.isChecked() == true;
But it gives error.
And then I need a if
so that if said RadioButton is "checked", I inserted it in the table.
So I did it:
ContentValues registronuevo = new ContentValues();
registronuevo.put("N", nombre);
registronuevo.put("C", curso);
if(r1 == true){
registronuevo.put("R1", r1);
}
registronuevo.put("P4", cuatro);
registronuevo.put("P5", cinco);
But the if also gives error.
EDITED:
Code to load the results:
public void cargar() {
DB baseHelper = new DB(this, "DEMODB", null, 1);
SQLiteDatabase db = baseHelper.getReadableDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from Datos", null);
int cantidad = c.getCount();
int i = 0;
String[] arreglo = new String[cantidad];
if(c.moveToFirst()){
do{
String linea = c.getInt(0)+"Nombre: "+ c.getString(1)+", Curso:"+c.getString(2)+", 1. R/:"+(c.getInt(c.getColumnIndex("R1"))>0?true:false)+ ", 4. R/:"+c.getString(4)+", 5. R/: "+c.getString(5);
arreglo[i] = linea;
i++;
}while (c.moveToNext());
}
ArrayAdapter<String>adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arreglo);
ListView lista = (ListView) findViewById(R.id.lista);
lista.setAdapter(adapter);
}
}