在同一个Android Activity中,通过按钮切换两个GUI界面,是否可能?

huangapple go评论79阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月28日 07:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63625476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定