Android - Wizard Type Activity With Adapter Backed Data
Solution 1:
Here is an educated guess at what might work.
I'm not sure if there are other view's that are easy to bind to like a listview, so I'll try and modify your example to work with a listview. First, If you make the Listview itself fill_parent and make the child item inside the listview Fill_parent, you'll basically end up with a listview that can display one child item only. Then you can try the following:
Alter getCount
I believe getCount(...)
is used to determine how many rows of data should show. Typically, we want this set to the count/size of the ArrayList we're using. In your case, I think you'd want it set to 1 as you only want one question to show at a time.
Create tracker for question
You'll need to create a tracker for which question you are currently on so you know which question to display. For this, you'll need a simple int questionTracker
variable, that you could increment everytime they answer/pass/skip a question.
Modify getView(...) to show the correct Question
In the getView(...) call, you'll need to populate the screen with the correct question, which will be based on your tracker. Something like this
@Override public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View questionView = inflater.inflate(R.layout.question, parent);
//Get the next question
Question currentQuestion = questions.get(questionTracker);
//Fill the fields in the inflated layout with the data from the Question object
TextView questionField = questionView.findViewById(R.id.questionText)
questionField.setText(Question.question);
return questionView;
}
Forcing question to change
The tricky part will be forcing the view to re-draw after you've hit next/pass/answered a qestion. You may be able to manually call getView(...), though I've never done it, so I'm not sure.
Post a Comment for "Android - Wizard Type Activity With Adapter Backed Data"