case表达式必须是常量表达式。在R.id.上获得错误*

时间:2016-03-26 13:25:47

标签: android eclipse

我被困在一个项目上;并且无法理解错误。请帮助我。我在每个R.id上获得Case表达式必须是常量表达式,我在这里分享代码。

我在每个Case R.id上收到此错误;请建议

public void onClick(View v) {
    int currentBgColor = PreferencesUtils.getBgColor(this);
    switch (v.getId()) {
    case R.id.btn_home:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        dismissMainCling(v);
        toggle();
        break;
    case R.id.btn_bookmark:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        boolean isBookmarked = false;
        for (Bookmark bm : mBookmarkList) {
            if (bm.partId == mCurrentPart && bm.chapId == mCurrentChap) {
                isBookmarked = true;
                break;
            }
        }
        if (isBookmarked) {
            showUnBookmarkDialog(mCurrentPart, mCurrentChap);
        } else {
            showSaveBookmarkDialog(mCurrentPart, mCurrentChap);
        }
        break;
    case R.id.btn_bm_list:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        // toggleSecondary();
        break;
    case R.id.btn_background:
        if (!isShowBgSelect) {
            showBgSelector();
            isShowBgSelect = true;
        } else {
            hideBgSelector(true);
            isShowBgSelect = false;
        }
        mBtnBgSelect.setEnabled(false);
        mBtnBgSelect.setSelected(true);
        break;
    case R.id.btn_fullscreen:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        if (isFullScreen) {
            showController();
            mFullScreenButton.setEnabled(false);
            isFullScreen = false;
        } else {
            hideController();
            isFullScreen = true;
        }
        break;
    case R.id.btn_home_slidingmenu_left:
        toggle();
        break;
    case R.id.btn_home_slidingmenu_right:
        // toggleSecondary();
        break;
    case R.id.btn_bg_white:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        if (currentBgColor != Constants.BG_COLOR_WHITE) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_WHITE);
            loadPart(mCurrentPart, mCurrentChap);
        }
        break;
    case R.id.btn_bg_khaki:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        if (currentBgColor != Constants.BG_COLOR_KHAKI) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_KHAKI);
            loadPart(mCurrentPart, mCurrentChap);
        }
        break;
    case R.id.btn_bg_sepia:
        if (isShowBgSelect) {
            hideBgSelector(false);
            isShowBgSelect = false;
        }
        if (currentBgColor != Constants.BG_COLOR_SEPIA) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_SEPIA);
            loadPart(mCurrentPart, mCurrentChap);
        }
        break;
    case R.id.btn_about:
        showAboutDialog();
        break;
    case R.id.tv_contact_us:
        Intent email = new Intent(Intent.ACTION_SEND);
        email.putExtra(Intent.EXTRA_EMAIL, new String[] { getResources()
                .getString(R.string.dialog_about_email) });
        email.putExtra(Intent.EXTRA_SUBJECT,
                getText(R.string.contact_prefix) + " "
                        + getText(R.string.app_name));
        email.setType("message/rfc822");
        startActivity(Intent.createChooser(email,
                getText(R.string.contact_chooser)));
        break;
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int currentBgColor = PreferencesUtils.getBgColor(this);
    switch (item.getItemId()) {
    case android.R.id.home:
        toggle();
        return true;
    case R.id.menu_bookmark:
        boolean isBookmarked = false;
        for (Bookmark bm : mBookmarkList) {
            if (bm.partId == mCurrentPart && bm.chapId == mCurrentChap) {
                isBookmarked = true;
                break;
            }
        }
        if (isBookmarked) {
            showUnBookmarkDialog(mCurrentPart, mCurrentChap);
        } else {
            showSaveBookmarkDialog(mCurrentPart, mCurrentChap);
        }
        return true;
    case R.id.menu_bookmarked_chap:
        // toggleSecondary();
        return true;
    case R.id.menu_bg_white:
        if (currentBgColor != Constants.BG_COLOR_WHITE) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_WHITE);
            loadPart(mCurrentPart, mCurrentChap);
        }
        return true;
    case R.id.menu_bg_khaki:
        if (currentBgColor != Constants.BG_COLOR_KHAKI) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_KHAKI);
            loadPart(mCurrentPart, mCurrentChap);
        }
        return true;
    case R.id.menu_bg_sepia:
        if (currentBgColor != Constants.BG_COLOR_SEPIA) {
            PreferencesUtils.saveBgColor(this, Constants.BG_COLOR_SEPIA);
            loadPart(mCurrentPart, mCurrentChap);
        }
        return true;
    case R.id.menu_about:
        showAboutDialog();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    if (isShowBgSelect) {
        hideBgSelector(false);
        isShowBgSelect = false;
    }
    return super.onPrepareOptionsMenu(menu);

}

@Override
protected void onDestroy() {
    super.onDestroy();

}

0 个答案:

没有答案