//base class that holds data
public class QuestionWithAnswers {
public String question;
public int rightAnswer = 0;
List<String> answers = new ArrayList(4);
public QuestionWithAnswers(String question, int rightAnswer, List<String> answers) {
this.question = question;
this.rightAnswer = rightAnswer;
this.answers.addAll(answers);
}
public QuestionWithAnwsers(String question, int rightAnswer, String answers) {
this.question = question;
this.rightAnswer = rightAnswer;
this.answers.addAll(Arrays.asList(answers));
}
}
Then in your adapter:
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
final Context context;
final List<QuestionWithAnswers> data;
public MyExpandableListAdapter(Context context, List<QuestionWithAnswers> data) {
this.context = context;
this.data = data;
}
@Override
public int getGroupCount() {
return data.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return data.get(groupPosition).answers.size();
}
@Override
public QuestionWithAnswers getGroup(int groupPosition) {
return data.get(groupPosition);
}
@Override
public String getChild(int groupPosition, int childPosition) {
return data.get(groupPosition).answers.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
//processing views
return SomeView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
//processing views
int rightAnswer = data.get(groupPosition).rightAnswer;
if (childPosition == rightAnswer){
textViewWithAnswer.setTextColor(Color.GREEN);
} else {
textViewWithAnswer.setTextColor(Color.RED);
}
return SomeView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
implement getGroupView
and getChildView
methods