Android中使用ViewFipperAndroid、ViewFipper

2023-09-04 12:17:08 作者:朕略萌~_~

我需要创建一个问题巫师ViewFlipper的帮助,使用户可以很容易的问题之间导航。我需要动态地生成每个问题的看法。每个视图将包含一个TextView(提问)单选按钮(选项为答案)和按钮('下一步'和'previous键可在各视图之间翻转)。

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:

在Viewflipper,我看到的布局是在XML文件中已经定义。谁能帮我如何自动生成并正确设置值的观点。

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.

问候 DJ

推荐答案

我会做你的位置:

请我自己的观点类,它的参数,什么是需要得到初始化与当前的问题 实施在活动中 ViewSwitcher.ViewFactory 接口为了建立视图下一个或previous问题 使用一个 ViewSwitcher 的小部件,让你从一个问题切换另一个 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

有关于如何使用ImageSwitcher小部件(开始的这个)。你只需要他们适应更广泛的ViewSwitcher。

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.

有关该解决方案在ViewFlipper所述的好处是,你将不必担心内存时,你QUIZZ有100个问题,你需要创建相应的解答所有的100次。

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.