Well, the first thing to say is that by definition when you use a RadioButton
(or a group of them) is to group items that are excluded from each other (there is only a single selection). I think it would be better for you to use CheckBox
Now specifically with your question, the answer is somewhat complicated. I once did it and it went something like this:
First : In your database as you indicate, you need an indicator that will be modified when you select an item from the list.
Second : At this point I assume you have an xml where you define the components (or form) of each item on the list.
Third : Having the 2 previous elements, you must have an Object (Java class) that has the columns of your table (I see that you are not using an ORM), therefore you will have to design a method that travels your cursor and loads an array of objects of the type you're driving. For example, if I have a Products table in my BDD I must have a Product object in my model and a method like this to move from a cursor to my object model, this method should be applied for each iteration that is done in the cursor
private Producto cursorToProducto(Cursor cursor) {
Producto p = new Producto();
p.setId(cursor.getInt(0));
p.setNombre(cursor.getString(1));
p.setUnidades(cursor.getInt(2));
p.setPrecio(cursor.getDouble(3));
p.setImporteImpuesto(cursor.getDouble(4));
p.setImpuestoAplicado(cursor.getDouble(5));
p.setCod_impuesto(cursor.getString(6));
p.setMarcadorTachado(cursor.getInt(8));
return p;
}
Implementation in the path of Cursor
:
while (!cursor.isAfterLast()) {
Producto p = cursorToProducto(cursor);
//retorno es una lista tipo List<Producto>
retorno.add(p);
cursor.moveToNext();
}
Fourth : Instead of SimpleCursorAdapter
I implemented a Adapter
custom of the type of object I'm working on
public class ProductArrayAdapter extends ArrayAdapter<Producto> {
private LayoutInflater inflater;
private Context context;
...
}
This point is extensive and is the most complicated, I recommend reading this post where they explain it very well.
Fifth : Specifically in this method getView
of your ArrayAdapter
you must include the statements so that when the CheckBox
is activated the record in the database is updated, something like this
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Producto p = (Producto) cb.getTag();
p.setSelected(cb.isChecked());
//evaluar el retorno de cb.isChecked() si es cierto
//ejecutar la rutina de update en BDD
}
});
Likewise. right there you can execute the instructions for the cases in which the item is already selected. Disable CheckBox
for example.
After all this, the ArrayAdapter
itself should show you the data in an appropriate way, as long as you correctly execute your update routines based on the CheckBox
events
I hope I help you.