失敗,我有以下開關:switch語句中嵌套類型
我groupPosition是0和childPosition爲1:
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
if (NetworkManager.isNetworkAvailable(this)) {
new UserAwayTask().execute();
} else
Toast.makeText(this, "Network not available", Toast.LENGTH_LONG).show();
break;
case 1:
selection = null;
selectionArgs = null;
break;
case 2:
selection = Employee.COL_COUNTRY + " IS ? COLLATE NOCASE";
selectionArgs = new String[]{valueReceived};
}
case 1:
selection = Employee.COL_DEPARTMENT + " IS ? COLLATE NOCASE";
selectionArgs = new String[]{valueReceived};
break;
case 2:
empIDList = GetAllTeamLeaders.teamLeaders(this, TeamLeader.COL_TEAMMEMBERID, TeamLeader.COL_TEAMLEADERNAME + " IS ? ", new String[]{valueReceived});
selection = Employee.COL_EMPID + " IN (" + TextUtils.join(",", Collections.nCopies(empIDList.size(), "?")) + ")";
selectionArgs = empIDList.toArray(new String[empIDList.size()]);
break;
}
但每次我的選擇是:部門是什麼? COLLATE NOCASE ,選擇參數來自外部開關的情況1。
所以這個:如果我評論外側開關的情況下,1和2的情況下
case 2:
selection = Employee.COL_COUNTRY + " IS ? COLLATE NOCASE";
selectionArgs = new String[]{valueReceived};
但是我得到期望的結果:
case 1:
selection = Employee.COL_DEPARTMENT + " IS ? COLLATE NOCASE";
selectionArgs = new String[]{valueReceived};
break;
是越來越執行代替。
我在這裏錯過了什麼?
你缺少break語句的情況下0: – arados
你需要在'情況下,'之開關語句後分號和'break' 0'或者它會在完成時直接進入'情況1'。 – lurker