1.自定义一个枚举集合类
public class EnumUnit { public enum BoxStatus { offline("离线", 0), online("在线", 1); private String key; private int value; BoxStatus(String key, int value) { this.key = key; this.value = value; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } } public enum DeviceStatus{ safe("优", 0), warn("良", 1),danger("差",2); private String key; private int value; DataStatus(String key, int value) { this.key = key; this.value = value; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } }
}
if (boxStatus == EnumUnit.BoxStatus.offline.getValue()) {
//离线
imState.setImageResource(R.mipmap.offline);
}else if (boxStatus== EnumUnit.BoxStatus.online.getValue()) {
//在线 imState.setImageResource(R.mipmap.online); }
本文介绍了一种自定义枚举集合类的方法,并通过两个具体示例:设备状态和盒子状态来展示如何定义枚举类型及其属性。此外,还提供了在实际代码中如何使用这些枚举类型的实例。
1423

被折叠的 条评论
为什么被折叠?



