1
I’m making an app with questions and answers, I have a radiogroup, a textview and 3 buttons: confirm, next and back.
I am trying to get once the question is answered, when returning in that question the answer is shown in the radiogroup selections.
But when I return the question the condition not to let select a new answer is applied, but to show the radio button checked not.
public void onClick(View v) {
switch (v.getId()){
case R.id.button_next:
int_lei=Integer.parseInt(temp_lei);
int_lei ++;
temp_lei= String.valueOf(int_lei);
AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "admin", null, 1);
SQLiteDatabase BasedeDados = admin.getWritableDatabase();
Cursor consulta1 = BasedeDados.rawQuery("select * from Escriturario where Lei="+temp_lei, null);
consulta1.moveToFirst();
Pergunta.setText(consulta1.getString(1));
rb1.setText(consulta1.getString(2));
rb2.setText(consulta1.getString(3));
rb3.setText(consulta1.getString(4));
rb4.setText(consulta1.getString(5));
rb5.setText(consulta1.getString(6));
feito = consulta1.getInt(8);
if(feito != 6){
rg.check(feito);
rb1.setClickable(false);
rb2.setClickable(false);
rb3.setClickable(false);
rb4.setClickable(false);
rb5.setClickable(false);
bt3.setClickable(false);
}
else{
rg.clearCheck();
rb1.setClickable(true);
rb2.setClickable(true);
rb3.setClickable(true);
rb4.setClickable(true);
rb5.setClickable(true);
bt3.setClickable(true);
}
break;
case R.id.button_back:
int_lei=Integer.parseInt(temp_lei);
int_lei --;
temp_lei= String.valueOf(int_lei);
if(1 <= int_lei) {
admin = new AdminSQLiteOpenHelper(this, "admin", null, 1);
BasedeDados = admin.getWritableDatabase();
consulta1 = BasedeDados.rawQuery("select * from Escriturario where Lei=" + temp_lei, null);
consulta1.moveToFirst();
Pergunta.setText(consulta1.getString(1));
rb1.setText(consulta1.getString(2));
rb2.setText(consulta1.getString(3));
rb3.setText(consulta1.getString(4));
rb4.setText(consulta1.getString(5));
rb5.setText(consulta1.getString(6));
feito = consulta1.getInt(8);
if(feito != 6){
rg.check(feito);
rb1.setClickable(false);
rb2.setClickable(false);
rb3.setClickable(false);
rb4.setClickable(false);
rb5.setClickable(false);
bt3.setClickable(false);
}
else{
rg.clearCheck();
rb1.setClickable(true);
rb2.setClickable(true);
rb3.setClickable(true);
rb4.setClickable(true);
rb5.setClickable(true);
bt3.setClickable(true);
}
}
break;
case R.id.button_validate:
admin = new AdminSQLiteOpenHelper
(this, "admin", null, 1);
BasedeDados = admin.getWritableDatabase();
consulta1 = BasedeDados.rawQuery("select * from Escriturario where Lei=" + temp_lei, null);
consulta1.moveToPosition(int_lei);
resposta = consulta1.getInt(7);
int int_resposta = -1;
switch(rg.getCheckedRadioButtonId()){
case R.id.rb1:
int_resposta = 1;
break;
case R.id.rb2:
int_resposta = 2;
break;
case R.id.rb3:
int_resposta = 3;
break;
case R.id.rb4:
int_resposta = 4;
break;
case R.id.rb5:
int_resposta = 5;
break;
}
ContentValues registro = new ContentValues();
registro.put("feito", int_resposta);
BasedeDados.update("Escriturario", registro, "Lei =" + temp_lei, null);
if (resposta == int_resposta) {
Toast.makeText(this, "Resposta correta", Toast.LENGTH_LONG).show();
}
if (resposta != int_resposta) {
Toast.makeText(this, "Resposta incorreta", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this, "Selecione uma resposta", Toast.LENGTH_SHORT).show();
}
rb1.setClickable(false);
rb2.setClickable(false);
rb3.setClickable(false);
rb4.setClickable(false);
rb5.setClickable(false);
bt3.setClickable(false);
}
Could help me get to the expected behavior.