gpt4 book ai didi

java - 我的 switch 语句没有返回任何内容?

转载 作者:行者123 更新时间:2023-12-02 04:22:05 25 4
gpt4 key购买 nike

我从警报对话框中选择“Left”,并将其放入 ConvertStatusToCode 函数后应该重新运行“4”,但事实并非如此?

final String[] status = {"Left"};

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Pick a Status");
builder.setItems(status, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
BookingStatus = convertStatusToCode(status[which]);

这是我的convertStatusToCode函数,但它没有重新调整它应该返回的“4”。


private String convertStatusToCode(String status) {

switch (status) {
case "Processing":
i = "0";
break;
case "Room is Allotted":
i = "1";
break;
case "Sorry All Rooms Are Full":
i = "2";
break;
case "Living":
i = "3";
break;
case "Left":
i = "4";
break;
}
return i;
}

最佳答案

它应该看起来像这样

  String getStatusCode(String status) {
switch (status) {
case "Processing":
return "0";
case "Room is Allotted":
return "1";
case "Sorry All Rooms Are Full":
return "2";
case "Living":
return "3";
case "Left":
return "4";
default:
return "default_value";
}
}

关于java - 我的 switch 语句没有返回任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56630081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com