I've had problems with the spinner because the setSeletion () method does not work, I do not know the reasons, but I think it's because of the popular way, that's why I use you to give me ideas, for that I've already used several methods, which would be the correct way to work with spinners, from filling up to consulting a previously saved value,
This is my code to load the spinner, nothing of the ordinary:
public void SPPersona(){
SQLiteDatabase db = openOrCreateDatabase("SAICoffeeSQL", MODE_PRIVATE, null);
String qryTP = "select _id, Tipo_persona from TB_Tipo_persona";
Cursor cTP = db.rawQuery(qryTP,null);
SimpleCursorAdapter cTPA = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cTP, new String[] {"Tipo_persona"}, new int[] {android.R.id.text1} );
cTPA.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sptipper.setAdapter(cTPA);
}
This other is to consult:
private void consulta(int id){
SQLiteDatabase db = openOrCreateDatabase("SAICoffeeSQL", MODE_PRIVATE, null);
String mqry = "select * from Creditos_productores where _id = " + id;
cursor = db.rawQuery(mqry,null);
while(cursor.moveToNext()) {
int tp = Integer.valueOf(cursor.getString(cursor.getColumnIndex("Id_tipo")));
sptipper.setSelection(tp);
}
}