Good afternoon, I have a problem with RadioGroup in a listview. Next, when I mark a RadioButtom and use the scroll of my listview, the markup I made appears on another RadioButto and not on what I had selected. Here is the code for my adapter:
class AdapterAmcPersonalizada extends BaseAdapter {
private final List<AvaliacaoMensal> mensal;
private final Activity act;
private AvaliacaoMensal flag;
public AdapterAmcPersonalizada(List<AvaliacaoMensal> mensal, Activity act) {
this.mensal = mensal;
this.act = act;
}
@Override
public int getCount() {
return mensal.size();
}
@Override
public Object getItem(int position) {
return mensal.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = act.getLayoutInflater().inflate(R.layout.activity_layout_lista_amc, parent, false);
final AvaliacaoMensal mensalAmc = mensal.get(position);
//pegando as referências das Views
TextView potencial = (TextView) view.findViewById(R.id.potencialLetra);
TextView questao = (TextView) view.findViewById(R.id.questao);
TextView titulo = (TextView) view.findViewById(R.id.titulo);
RadioButton simButton = (RadioButton) view.findViewById(R.id.sim);
RadioButton naoButton = (RadioButton) view.findViewById(R.id.nao);
RadioButton naButton = (RadioButton) view.findViewById(R.id.na);
//populando as Views
potencial.setText(String.valueOf(mensalAmc.getPotencial()));
questao.setText(String.valueOf(mensalAmc.getQuestao()));
titulo.setText(String.valueOf(mensalAmc.getTitulo()));
RadioGroup radioGroupAmc = (RadioGroup) view.findViewById(R.id.radioGroupAmc);
flag = mensal.get(position);
radioGroupAmc.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case sim:
flag.radioButtonValues[0] = true;
flag.radioButtonValues[1] = false;
flag.radioButtonValues[2] = false;;
// trata radioValor1
break;
case nao:
flag.radioButtonValues[0] = false;
flag.radioButtonValues[1] = true;
flag.radioButtonValues[2] = false;
// trata radioValor2
break;
case na:
flag.radioButtonValues[0] = false;
flag.radioButtonValues[1] = false;
flag.radioButtonValues[2] = true;
// trata radioValor3
break;
}
}
});
if( flag.radioButtonValues[0] == true )
{
simButton.setChecked(true);
naoButton.setChecked(false);
naButton.setChecked(false);
} else {
if(flag.radioButtonValues[1] == true ){
naoButton.setChecked(true);
simButton.setChecked(false);
naButton.setChecked(false);
} else {
if(flag.radioButtonValues[2] == true ){
naButton.setChecked(true);
simButton.setChecked(false);
naoButton.setChecked(false);
}else {
simButton.setChecked(false);
naoButton.setChecked(false);
naButton.setChecked(false);
}
}
}
In the following snippet, I check the position that is in my listview (flag) and check the value that is within radioButtonValues[]
.
if( flag.radioButtonValues[0] == true )
{
simButton.setChecked(true);
naoButton.setChecked(false);
naButton.setChecked(false);
} else {
if(flag.radioButtonValues[1] == true ){
naoButton.setChecked(true);
simButton.setChecked(false);
naButton.setChecked(false);
} else {
if(flag.radioButtonValues[2] == true ){
naButton.setChecked(true);
simButton.setChecked(false);
naoButton.setChecked(false);
}else {
simButton.setChecked(false);
naoButton.setChecked(false);
naButton.setChecked(false);
}
}
}
Rating Class Mental:
class AvaliacaoMensal {
private String questao;
private char potencial;
private String titulo;
boolean[] radioButtonValues = new boolean[3];
//Gets e sets
But it is not working as expected because the dialing is going to another RadioGroup, can anyone help me?