In a question I made here in StackOverflow a few days ago I was instructed to use the ExpendedListView component to render a dynamic list of items.
After the implementation I saw that the items in the list were grouped correctly, but now I need to implement the return of the tags and I'm having a new problem.
What's happening is that my list loads perfectly, but I can not get RadioButtons to behave properly because they do not seem to be grouped, so it's possible to mark more than one item in the list. The code below shows how I'm doing to load list items into ExpandedListView and how I'm handling the click:
final List<QuestoesRequest> questoes = questaoService.getListQuestoes(getIdAvaliacao());
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
expListView.setAdapter(new QuestaoExpandedListAdapter(
this, questoes));
//Define um listener para tratar a selecção das respostas
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
boolean b = expListView.isItemChecked(childPosition);
RadioButton answerText = (RadioButton) v.findViewById(R.id.answerText);
answerText.setChecked(true);
//Indica que esta resposta foi seleccionada
int idQuestao = questoes.get(groupPosition).getIdQuestao();
int idAlternativa = questoes.get(groupPosition)
.getAlternativasRequests().get(childPosition).idAlternativa;
respostasQuestao.put(idQuestao, idAlternativa);
return true;
}
});
Although I can visually display the RadioButton's markup, I can not undo it if I choose another option.
Any suggestions? Hugs!