1、定义枚举
public enum BankNameEnum {
ICBC("ICBC", "工商银行", R.mipmap.bank_icbc),
ABC("ABC", "农业银行", R.mipmap.bank_abc),
BOC("BOC", "中国银行", R.mipmap.bank_boc),
CCB("CCB", "建设银行", R.mipmap.bank_ccb),
CMBCHINA("CMBCHINA", "招商银行", R.mipmap.bank_cmb),
POST("POST", "邮政储蓄", R.mipmap.bank_psbc),
CITIC("CITIC", "中信银行", R.mipmap.bank_citic),
CEB("CEB", "光大银行", R.mipmap.bank_cebbank),
BOCO("BOCO", "交通银行", R.mipmap.bank_comm),
CIB("CIB", "兴业银行", R.mipmap.bank_cib),
CMBC("CMBC", "民生银行", R.mipmap.bank_cmbc),
PINGAN("PINGAN", "平安银行", R.mipmap.bank_spabank),
CGB("CGB", "广发银行", R.mipmap.bank_cgb),
BCCB("BCCB", "北京银行", R.mipmap.bank_bccb),
HXB("HXB", "华夏银行", R.mipmap.bank_hxbank),
SPDB("SPDB", "浦发银行", R.mipmap.bank_spdb),
SHB("SHB", "上海银行", R.mipmap.bank_shbank),
DEFAULT("DEFAULT", "无名银行", R.mipmap.ic_kaqi);
// 成员变量
private String bankid;
private String bankname;
private int drawId;
BankNameEnum(String bankid, String bankname, int drawId) {
this.bankid = bankid;
this.bankname = bankname;
this.drawId = drawId;
}
public String getBankid() {
return bankid;
}
public void setBankid(String bankid) {
this.bankid = bankid;
}
public String getBankname() {
return bankname;
}
public void setBankname(String bankname) {
this.bankname = bankname;
}
public int getDrawId() {
return drawId;
}
public void setDrawId(int drawId) {
this.drawId = drawId;
}
@Override
public String toString() {
return "BankNameUtill{" +
"bankid='" + bankid + '\'' +
", bankname='" + bankname + '\'' +
", drawId=" + drawId +
'}';
}
}
2、 使用方法:
BankNameEnum bankNameEnum = null ;
BankNameEnum[] enums = BankNameEnum.values();
for (BankNameEnum bEnum : enums) {
if (bEnum.getBankid().equals(bankId)) {
bankNameEnum = bEnum;
break;
}else {
bankNameEnum = Enum.valueOf(BankNameEnum.class, "DEFAULT") ;
}
}
3、获取值
String bankName = bankNameEnum.getBankname();
int drawId = bankNameEnum.getDrawId();
网友评论