问题
I need to create a question wizard with the help of ViewFlipper so that users can navigate between the questions easily. I need to dynamically generate the views for each questions. Each of the view will contain a Textview(for questions) Radio Buttons(Options for answer) and Buttons('Next' and 'Previous' buttons to flip between each views).
Here is the model of wizard I want to create:
In Viewflipper, I see that the layout is already defined in the XML file. Can anyone help me how to generate it automatically and set the values correctly to the view.
regards dj
回答1:
What I would do in your position:
- Make my own view class that takes as parameter what is needed to get initialised with the current question
- Implement the ViewSwitcher.ViewFactory interface in the Activity in order to build the view for the next or previous question
- Use a ViewSwitcher widget to allow you to switch from a question to another
There are quite a lot of examples on how to use the ImageSwitcher widget (starting with this one). You just need to adapt them to a more general ViewSwitcher.
The good thing about that solution over the ViewFlipper one is that you won't have to worry about memory when your quizz has 100 questions and you need to create all 100 views corresponding to your questions.
来源:https://stackoverflow.com/questions/4365682/using-viewfipper-in-android