简体   繁体   English

Android-我在Android中有5个开关小部件,我想使用每个开关及其组合来显示结果

[英]Android- I have 5 switch widget in android I want to use each one of the switch and their combination to show the result

I am having a problem with writing cases for each switch(whether it is on or off) using if-else condition. 我在使用if-else条件为每个开关(无论打开还是关闭)编写保护套时遇到问题。 For example, there are three switches(widget) in android one simple case is only one switch is working at a time, another case is in a pair like 1 and 2 working or 2 and 3 working or 1 and 3 working or all three working together on the basis of that wanna show the results which are the switches on/working at a time. 例如,Android中有三个开关(小部件),一个简单的案例是一次只有一个开关在工作,另一个案例是一对,如1和2或2和3或1和3或全部三个要一起显示结果,即一次打开/工作。 So using if-else condition method for 8 or more switches is an impossible task. 因此,对8个或更多开关使用if-else条件方法是不可能完成的任务。 So I want to know some efficient and good method of making such conditions possible. 因此,我想知道一些有效且良好的方法来使此类条件成为可能。

If you look closely, those switches will resemble words in binary format. 如果仔细观察,这些开关将类似于二进制格式的单词。 Following your eight switches example, let's say 10010101 represent the disposition of those, where the switch 0 is on, 1 is off and so on. 以您的八个开关示例为例,假设10010101代表了这些开关的布置,其中开关0处于打开状态,开关1处于关闭状态,依此类推。

Make each switch affect one bit in an Integer, being 0 off and 1 on for example and you can use that very number in a switch construct to handle each case. 使每个开关影响整数中的一位,例如,关闭0并打开1 ,您可以在开关构造中使用该数字处理每种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM