首页 > 解决方案 > 在 android studio 中使用一个按钮在片段之间导航

问题描述

我正在 android studio 中开发一个应用程序(使用 Java),它需要在 3 个屏幕之间切换,直到它到达游戏。例如:

Screen A (user input and a question + button to continue) -> when pressing the button the input pass to the screen B
Screen B (user input and a question + button to continue) -> when pressing the button the input pass to the screen C
Screen C (user input and a question + button to continue) -> when pressing the button the input saved in DB and we start a new game.

这就像注册过程,但有多个屏幕。我的问题是如何使用片段来实现它?我认为由于屏幕是相似的(唯一改变的是问题)片段将是最好的选择。但是当我尝试实现它时,我没有成功让按钮在 3 个屏幕之间切换,只有 2 个。我还阅读了 ViewPager2,但是当我尝试使用它时发生了多个错误。另外,每个片段都需要保留前一个片段的输入+播放不同的记录。有没有什么好的实现来实现这个场景?

标签: javaandroidandroid-fragmentsandroid-activityandroid-viewpager2

解决方案


推荐阅读