Android ViewFlipper 与 Intent
是否可以在两个活动之间使用 ViewFlipper,并同时在它们之间发送参数?
就像,在第一个视图上,使用两个按钮,根据哪个按钮,它应该切换到总视图(使用 ViewFlipper),并根据按下的按钮使用一些不同的逻辑。
提前致谢。
Is it possible to use ViewFlipper between two activities, and at the same send parameters between them?
Like, on the first view, two buttons are used, depending on what button, it should be switched over to the over view (using ViewFlipper) and using some different logic depending on the button pressed.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只需创建两个类并让它们扩展所需的布局。在每个类中你可以有不同的逻辑。然后,您的 Activity 将仅保留 ViewFlipper 和切换到下一个/上一个的逻辑。
第一个视图
第二个视图
然后,当您需要在第一个视图或第二个视图上更改视图时,您可以调用
flipper.showNext()
或Flipper.showPrevious()
编辑
要在两个视图之间传递数据,您可以为此目的在 Activity 类中实现一些方法,然后让两个视图持有对该 Activity 的引用。另一种选择是创建两个视图必须实现的接口:
I would just create two classes and have them inflate the desired layout. In each class you could have the different logic. Your activity would then only hold the ViewFlipper and the logic for switching to next/previous.
First View
Second View
Then when you need to change view when on either FirstView or SecondView, you call
flipper.showNext()
orflipper.showPrevious()
EDIT
To pass data between the two views, you can either implement some methods in the activity class for this purpose and then let the two views hold a reference to the activity. Another alternative is to create an interface that the two views must implement:
名称应该告诉您。您可以在两个视图之间切换,而不是在两个意图之间切换。因此,最好尝试在两个视图之间切换,而不是在两个活动之间切换。
Name should tell you.You can flip between two views not between two intents.So better try to flip between two views rather than two activities.