错误:枚举开关大小写标签必须是枚举常量的非限定名称 [英] error: an enum switch case label must be the unqualified name of an enumeration constant

查看:156
本文介绍了错误:枚举开关大小写标签必须是枚举常量的非限定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:枚举开关大小写标签必须是枚举常量的不合格名称错误:案件标签重复

error: an enum switch case label must be the unqualified name of an enumeration constant error: duplicate case label

不用编译,帮帮我!

public class CardViewStyleSetting extends ThemedSetting {

    public CardViewStyleSetting(ThemedActivity activity) {
        super(activity);
    }

    public void show() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getActivity().getDialogStyle());
        final View dialogLayout = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_album_card_style, null);

        TextView dialogTitle = dialogLayout.findViewById(R.id.dialog_card_view_style_title);
        ((CardView) dialogLayout.findViewById(R.id.dialog_card_view_style)).setCardBackgroundColor(getActivity().getCardBackgroundColor());
        dialogTitle.setBackgroundColor(getActivity().getPrimaryColor());

        final RadioGroup rGroup = dialogLayout.findViewById(R.id.radio_group_card_view_style);
        final CheckBox chkShowMediaCount = dialogLayout.findViewById(R.id.show_media_count);
        final CheckBox chkShowAlbumPath = dialogLayout.findViewById(R.id.show_album_path);
        RadioButton rCompact = dialogLayout.findViewById(R.id.radio_card_compact);
        RadioButton rFlat = dialogLayout.findViewById(R.id.radio_card_flat);
        RadioButton rMaterial = dialogLayout.findViewById(R.id.radio_card_material);

        chkShowMediaCount.setChecked(Prefs.showMediaCount());
        chkShowAlbumPath.setChecked(Prefs.showAlbumPath());

        getActivity().themeRadioButton(rCompact);
        getActivity().themeRadioButton(rFlat);
        getActivity().themeRadioButton(rMaterial);
        getActivity().themeCheckBox(chkShowMediaCount);
        getActivity().themeCheckBox(chkShowAlbumPath);

        rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                final View v;
                switch (i) {
                    case R.id.radio_card_compact:
                        v = LayoutInflater.from(getActivity()).inflate(CardViewStyle.COMPACT.getLayout(), null);
                        v.findViewById(R.id.ll_album_info).setBackgroundColor(ColorPalette.getTransparentColor(getActivity().getBackgroundColor(), 150));
                        break;
                    case R.id.radio_card_flat:
                        v = LayoutInflater.from(getActivity()).inflate(CardViewStyle.FLAT.getLayout(), null);
                        v.findViewById(R.id.ll_album_info).setBackgroundColor(ColorPalette.getTransparentColor(getActivity().getBackgroundColor(), 150));
                        break;
                    case R.id.radio_card_material: default:
                        v = LayoutInflater.from(getActivity()).inflate(CardViewStyle.MATERIAL.getLayout(), null);
                        v.findViewById(R.id.ll_album_info).setBackgroundColor(getActivity().getCardBackgroundColor());
                        break;
                }

                ImageView img = v.findViewById(R.id.album_preview);
                img.setBackgroundColor(getActivity().getPrimaryColor());

                Glide.with(getActivity())   
    .load(R.drawable.donald_header)
                        .into(img);
String hexPrimaryColor = ColorPalette.getHexColor(getActivity().getPrimaryColor());
                String hexAccentColor = ColorPalette.getHexColor(getActivity().getAccentColor());

                if (hexAccentColor.equals(hexPrimaryColor))
                    hexAccentColor = ColorPalette.getHexColor(ColorPalette.getDarkerColor(getActivity().getAccentColor()));

                String textColor = getActivity().getBaseTheme().equals(Theme.LIGHT) ? "#2B2B2B" : "#FAFAFA";
                String albumPhotoCountHtml = "<b><font color='" + hexAccentColor + "'>420</font></b>";

                ((TextView) v.findViewById(R.id.album_media_count)).setText(StringUtils.html(albumPhotoCountHtml));
                ((TextView) v.findViewById(R.id.album_media_label)).setTextColor(getActivity().getTextColor());
                ((TextView) v.findViewById(R.id.album_path)).setTextColor(getActivity().getSubTextColor());

                v.findViewById(R.id.ll_media_count).setVisibility( chkShowMediaCount.isChecked() ? View.VISIBLE : View.GONE);
                chkShowMediaCount.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        v.findViewById(R.id.ll_media_count).setVisibility(b ? View.VISIBLE : View.GONE);
                    }
                });

                v.findViewById(R.id.album_path).setVisibility( chkShowAlbumPath.isChecked() ? View.VISIBLE : View.GONE);
                chkShowAlbumPath.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        v.findViewById(R.id.album_path).setVisibility(b ? View.VISIBLE : View.GONE);
                    }
                });

                ((TextView) v.findViewById(R.id.album_name)).setText(StringUtils.html("<i><font color='" + textColor + "'>PraiseDuarte</font></i>"));
                ((TextView) v.findViewById(R.id.album_path)).setText("~/home/PraiseDuarte");

                ((CardView) v).setUseCompatPadding(true);
                ((CardView) v).setRadius(2);

                ((LinearLayout) dialogLayout.findViewById(R.id.ll_preview_album_card)).removeAllViews();
                ((LinearLayout) dialogLayout.findViewById(R.id.ll_preview_album_card)).addView(v);
            }
        });

        switch (Prefs.getCardStyle()) {
            case CardViewStyle.COMPACT: rCompact.setChecked(true); break;
            case CardViewStyle.FLAT: rFlat.setChecked(true); break;
            case CardViewStyle.MATERIAL: default: rMaterial.setChecked(true); break;
        }

        builder.setNegativeButton(getActivity().getString(R.string.cancel).toUpperCase(), null);
        builder.setPositiveButton(getActivity().getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                CardViewStyle cardViewStyle;
                switch (rGroup.getCheckedRadioButtonId()) {
                    case R.id.radio_card_material:
                    default:
                        cardViewStyle = CardViewStyle.MATERIAL;
                        break;
                    case R.id.radio_card_flat:
                        cardViewStyle = CardViewStyle.FLAT;
                        break;
                    case R.id.radio_card_compact:
                        cardViewStyle = CardViewStyle.COMPACT;
                        break;
                }
                Prefs.setCardStyle(cardViewStyle);
                Prefs.setShowMediaCount(chkShowMediaCount.isChecked());
                Prefs.setShowAlbumPath(chkShowAlbumPath.isChecked());
                Toast.makeText(getActivity(), getActivity().getString(R.string.restart_app), Toast.LENGTH_SHORT).show();
            }
        });
        builder.setView(dialogLayout);
        builder.show();
    }
}

推荐答案

根据Java文档

EnumConstant中的标识符可以用名称来引用枚举常量.

The Identifier in a EnumConstant may be used in a name to refer to the enum constant.

所以我们仅在枚举的情况下才需要使用名称.

so we need to use the name only in case of an enum.

更改为此

switch (Prefs.getCardStyle()) {
    case COMPACT: rCompact.setChecked(true); break;
    case FLAT: rFlat.setChecked(true); break;
    case MATERIAL: default: rMaterial.setChecked(true); break;
}

这篇关于错误:枚举开关大小写标签必须是枚举常量的非限定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆