Java libs上的开关大小写错误

Java libs上的开关大小写错误,java,android,Java,Android,我在为我的Android应用程序实现库模块时出错。 它说: Constant expression required Resource IDs cannot be used in a switch statement in Android library modules less... (Ctrl+F1) Validates using resource IDs in a switch statement in Android library module. Resource IDs are

我在为我的Android应用程序实现库模块时出错。 它说:

Constant expression required Resource IDs cannot be used in a switch statement in Android library modules less... (Ctrl+F1) 
Validates using resource IDs in a switch statement in Android library module. Resource IDs are non final in the library projects since SDK tools r14, means that the library code cannot treat these IDs as constants.
这是我的代码:

private void changeWeekStart(@IdRes int selection) {
        switch (selection) {
            case R.id.action_week_start_saturday:
                CalendarUtils.sWeekStart = Calendar.SATURDAY;
                break;
            case R.id.action_week_start_sunday:
                CalendarUtils.sWeekStart = Calendar.SUNDAY;
                break;
            case R.id.action_week_start_monday:
                CalendarUtils.sWeekStart = Calendar.MONDAY;
                break;
        }
        PreferenceManager.getDefaultSharedPreferences(this)
                .edit()
                .putInt(CalendarUtils.PREF_WEEK_START, CalendarUtils.sWeekStart)
                .apply();
        supportInvalidateOptionsMenu();
        mCoordinator.reset();
    }
请帮我把开关箱换成if else代码。 谢谢。

只要你有一个案例,它就会成为if声明的条件;break语句将与if语句的closing}相对应

if (selection == R.id.action_week_start_saturday) {
    CalendarUtils.sWeekStart = Calendar.SATURDAY;
} else if (selection == R.id.action_week_start_sunday) {
    CalendarUtils.sWeekStart = Calendar.SUNDAY;
} else if (selection == R.id.action_week_start_monday) {
    CalendarUtils.sWeekStart = Calendar.MONDAY;
}
请注意,在switch case块中不提供默认大小写,因此,如果选择参数的值与您考虑的值不同,则CalendarUtils.sWeekStart可能不会被修改