0
Good afternoon, I have a problem with Radiogroup on a listview. Next, when I mark a Radiobuttom and use the scroll of my listview, the marking I made appears in another Radiobutto and not in what I had selected. Follow the code of 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 section, I check the position that is my listview (flag) and check the value that is within the 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);
}
}
}
Class Avaliacaomensal:
class AvaliacaoMensal {
private String questao;
private char potencial;
private String titulo;
boolean[] radioButtonValues = new boolean[3];
//Gets e sets
But it’s not working as expected, because the dialing is going to another Radiogroup, someone can help me?
Last
if
, insert aelse { naButton.setChecked(false); }
– viana
@acklay Pq? do not understand.
– Lucas Charles
I’m seeing that without the true but no false. You have to create a denial too if it’s not true. Then at the end you are creating an if without Else. Try adding Else if it is not true.
if(flag.radioButtonValues[2] == true ){
 naButton.setChecked(true);
} else { naButton.setChecked(false); }
– viana
@acklay So at last This I would have to put
}else {
 simButton.setChecked(false);
 naoButton.setChecked(false);
 naButton.setChecked(false);
 }
But it hasn’t changed at all =[– Lucas Charles
That’s right Lucas... I’m asking you to do it like this to see if it works! = D
– viana
@acklay Yes yes it makes sense. But it did not give no :(
– Lucas Charles
It also has the simButton button that you have to put simButton.setChecked(false) at some point.
– viana
Your logic is very strange. hehe
– viana
@acklay Wow ... I check in Flag position if certain radiobutton is marked, in case I’m setCheked on it. It was the best I could think of :(
– Lucas Charles
No need to compare if it is
true
, just doif(flag.radioButtonValues[0]){ ... bla bla bla}
.... That already means it’strue
. Look at the ramaral’s answer, maybe it solves your problem. Exactly what I was trying to say.– viana
@acklay sorry I responded, but I was already doing it when I saw your comments.
– ramaral
@ramaral Relax! The main goal of the OS is to work together to help others! I think we are fulfilling this. = D
– viana
@acklay I know, but I don’t like to meddle (I don’t see the need) when someone is already helping and is on the right track.
– ramaral
When editing the question with updated code with that of the answer you leave the answer meaningless. Whoever reads the question now will say that I to answer copied the question code.
– ramaral
@Lucascharles It’s not cool for you to edit a question by inserting answer content from people who tried to help you. This ends up invalidating the answers. The interesting thing is to talk and try to solve from what you already have.
– viana
What’s in the Evaluator class? You can show her content?!
– viana
@Okay acklay, I edited my question. :)
– Lucas Charles
Why are you using the
flag = mensal.get(position);
if you already have the endingAvaliacaoMensal mensalAmc = mensal.get(position)
;. I shouldn’t be comparing themensalAmc
– viana
@acklay my flag was picking up random values. I just don’t know pq. THANK YOU!
– Lucas Charles