英文:
Is it possible to toggle between 2 GUIs from the same Android Activity using a button?
问题
我正在编写我的第一个Android应用程序,它由一个单一的活动构成。这个活动创建一个服务器,监听数据,解码并处理数据,然后显示出来。我想以两种不同的方式显示服务器数据,在按钮按下时在它们之间切换(默认模式和调试器模式)。服务器需要始终保持运行。实现这一目标最简单的方式是什么?
模式A:这是应用程序的默认模式。它将从服务器接收到的消息中显示图标和相关信息给用户。包含一个按钮来切换到模式B。
模式B:当用户从模式A内部点击一个按钮时,应该触发此模式。它将隐藏模式A中的信息,并显示更详细的信息,例如原始十六进制数据以及消息中的其他文本信息。包含一个方法,可以切换回模式A。
英文:
I am writing my first android application that consists of a single activity. The activity creates a server, listens for data, decodes and proceesses the data, and displays it. I would like to display the server data two different ways, toggling between them with a button press. (default mode and debugger mode). The server needs to continue running at all times. What is the most simple way to do this?
Mode A: The default for the application. It will just display Icons and relevant information to the user from the messages recieved by the server. Contains a button to toggle mode B.
Mode B: this mode should be triggered when the user taps a button from within mode A. It will hide the information from mode A, and display more in depth information such as raw hex data, and additional information from the message as plain text. Contains a method to toggle back to mode A.
答案1
得分: 1
这是一个纯粹的前端,你可以在活动中有一个片段占位符,并在几个片段之间来回切换,每个片段应该有不同的XML UI布局,根据你的需要来设计你的图形界面。
此外,从“ViewModel”中打包你的布局视图,以便在片段之间过渡时不会触发服务器。
英文:
This is a pure front end, you can have a fragment placeholder in the activity and switch back and forth between a couple of fragments, each fragment should have a different XML UI layouts as you need your GUI.
Also, pack your layout views from a ViewModel
in order not to trigger the server while transitioning between fragments.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论