Android Inflate View Multiple Time Depending On Button State - Optimisation
StackOverflow community, I need your help (again) ! I created a custom class to quickly create View object (basically it's just a question displayed). Exemple : Title : Home Mess
Solution 1:
Create class what represent question item:
publicclassNode{
privatelong id;
private String question;
private String title;
privatelong yesId;
privatelong noId;
//Constructor, getter here....
}
You need adapter with list of question.
ArrayList<Node> questions = newArrayList<>();
NodeAdapteradapter=newNodeAdapter(questions, ...);
When you pressing button get next node id by answer (getYesId/getNoId). And if it last item create new by id or if not check is next id same as new next id.
//Create interface in your adapter or do what you want, but like thispublicvoidonNodeClicked(long nextId, int currentPosition){
Node next;
if(currentPosition == questions.size() - 1){
next = getNodeById(nextId);
question.add(next);
}else{
next = questions.get(position + 1);
if(nextId != next.getId()){
ArrayList<Node> remove = new ArrayList<>();
remove.addAll(position + 1, questions);
questions.removeAll(remove);
next = getNodeById(nextId);
question.add(next);
}
}
adapter.notifyDataSetChanged();
}
I hope it can help you)
Post a Comment for "Android Inflate View Multiple Time Depending On Button State - Optimisation"