Using ViewFipper in android

馋奶兔 提交于 2019-12-20 15:33:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!