在 Android 中制作一个类似应用程序的向导 [英] Make a wizard like application in Android

查看:29
本文介绍了在 Android 中制作一个类似应用程序的向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您认为这是在 Android 平台上执行类似应用程序的向导的最佳方式(用户可以使用下一步和后退按钮在屏幕之间导航,并且每个屏幕都必须保存一些状态数据).

Which you think is the best way of doing a wizard like application (user can navigate between screens with a next and back button, and each screen has to save some state data) in Android platform.

我主要有两种思路:

  1. 每个屏幕都有一个活动+视图,然后我通过调用每个活动来切换屏幕.这样做的好处是我可以使用系统后退按钮作为我的后退处理程序,而我不必自己处理,每个 Activity 都会保存它自己的状态.

  1. Having one activity+view for each screen and then i make the screen switch by calling each activity. What make this nice is that i can use the system back button as my back handler and i don't have to take care of that myself, aslo each activity will save it's own state.

有一个活动和多个视图,以及我在每次屏幕更改时切换视图的内容,这有助于我重用更多代码,但使保存状态变得一团糟.

Having one activity and many views, and what i switch views in each screen change, this helps me re-use more code, but makes saving states a mess.

你怎么看?在 Android 上执行此操作的最佳方法是什么?

What do you think? Which is the best way of doing this on Android?

推荐答案

我建议使用 2,因为它符合活动和视图的目标.在这种情况下保存状态很容易 - 如果您使用 MVC 模式,您可以简单地将模型对象传递给视图.每个视图都有它可以读/写的模型部分.无论您身在何处,模型都应始终具有当前状态.如果您被处置,只需保存模型.由于您在显示每个页面时已经从模型中读取数据,因此恢复会自动工作.

I suggest going with 2 as it fits the goal of activities and views. Saving state in this case is easy - if you use the MVC pattern, you can simply have a model object that is passed along to the views. Each view will have portions of the model that it can read/write. No matter where you are, the model should always have the current state. If you get disposed, just save the model. Restore works automatically since you already read from the model when you show each page.

这篇关于在 Android 中制作一个类似应用程序的向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆