private String getRealName(String nickName) { String realName = ""; switch (nickName) { case "SG": realName = "Necklace"; break; case "AX": realName = "Bracelet"; break; case "HX": realName = "Earrings"; break; default: realName = "Others"; break; } return realName; } } public void reader(String epc) { String upc = epc; //UpcUtils.getUPC(epc); Stock s; String abbreviation = ""; String nickName = upc.replaceAll("@+", ""); String slName = nickName.substring(0, 2); String realName = getRealName(slName); s = new Stock(upc, upc, realName, realName); s.setTime(FileUtil.getTimes()); s.setAbbreviation(abbreviation); //adapter.update(s); long count = Long.parseLong(btn_update.getText().toString()) + 1; btn_update.setText(String.valueOf(count)); }根据不同的case分别对btn_upload进行赋值怎么做
时间: 2024-01-05 16:03:19 浏览: 153
您可以在每个case语句中添加对btn_upload的赋值,比如:
```
switch (nickName) {
case "SG":
realName = "Necklace";
btn_upload.setText("Necklace");
break;
case "AX":
realName = "Bracelet";
btn_upload.setText("Bracelet");
break;
case "HX":
realName = "Earrings";
btn_upload.setText("Earrings");
break;
default:
realName = "Others";
btn_upload.setText("Others");
break;
}
```
这样,当getRealName()函数返回不同的realName时,btn_upload的文本内容也会相应地变化。
相关问题
private String getRealName(String nickName) { String realName = ""; switch (nickName) { case "SG": realName = "Necklace"; break; case "AX": realName = "Bracelet"; break; case "HX": realName = "Earrings"; break; default: realName = "Others"; break; } return realName; } } public void reader(String epc) { String upc = epc; //UpcUtils.getUPC(epc); Stock s; String abbreviation = ""; String nickName = upc.replaceAll("@+", ""); String slName = nickName.substring(0, 2); String realName = getRealName(slName); s = new Stock(upc, upc, realName, realName); s.setTime(FileUtil.getTimes()); s.setAbbreviation(abbreviation); //adapter.update(s); long count = Long.parseLong(btn_update.getText().toString()) + 1; btn_update.setText(String.valueOf(count)); }根据不同的case分别对btn_upload进行赋值
根据你提供的代码,我能看出这段代码是一个方法,其目的是根据输入的参数nickName来获取对应的realName,并在最后更新btn_update的文本内容。其中,nickName是一个字符串,根据不同的值,会进入不同的case语句进行处理。每个case都会给realName赋上不同的值,而最后的default语句则是在nickName不匹配任何一个case时的默认处理。最后,通过btn_update.setText()方法来更新btn_update的文本内容。
private String getRealName(String nickName) { String realName = ""; switch (nickName) { case "SG": realName = "SG"; break; case "AX": realName = "AX"; break; case "HX": realName = "HX"; break; default: realName = "Others"; break; } return realName; }public void reader(String epc) { ImportViewModel importViewModel=new ImportViewModel(); String upc = epc; //UpcUtils.getUPC(epc); Stock s; String abbreviation = ""; String nickName = upc.replaceAll("@+", ""); String slName = nickName.substring(0, 2); String realName = getRealName(slName); s = new Stock(upc, upc, realName, realName); s.setTime(FileUtil.getTimes()); s.setAbbreviation(abbreviation); //adapter.update(s); long count = Long.parseLong(btn_update.getText().toString()) + 1; btn_update.setText(String.valueOf(count)); }根据case更新btn_update
你可以在getRealName方法中添加更新btn_update的代码,例如:
private String getRealName(String nickName) {
String realName = "";
switch (nickName) {
case "SG":
realName = "SG";
break;
case "AX":
realName = "AX";
break;
case "HX":
realName = "HX";
break;
default:
realName = "Others";
break;
}
// 更新btn_update
long count = Long.parseLong(btn_update.getText().toString()) + 1;
btn_update.setText(String.valueOf(count));
return realName;
}
这样每次调用getRealName方法时,btn_update的值就会加1。
阅读全文