android – 必须是以下之一:View.VISIBLE,View.INVISIBLE,View.GONE [复制]

参见英文答案 > Not able to dynamically set the setVisibility() parameter2个
我正在保存并恢复我的一项活动中的视图可见性.我这样做是通过调用mButton.getVisibility()并将其保存在Bundle中.在onRestore中,我得到int值,它显示错误.
Must be one of: View.VISIBLE,View.INVISIBLE,View.GONE less... (Ctrl+F1) 
Reports two types of problems:
- Supplying the wrong type of resource identifier. For example,when calling Resources.getString(int id),you should be passing R.string.something,not R.drawable.something.
- Passing the wrong constant to a method which expects one of a specific set of constants. For example,when calling View#setLayoutDirection,the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.

代码编译并运行,没有错误

@Override
public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
    savedInstanceState.putInt("BUTTON_VISIBILITY",mButton.getVisibility());

    super.onSaveInstanceState(savedInstanceState);
}

public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    mButton.setVisibility(savedInstanceState.getInt("BUTTON_VISIBILITY"));
    // savedInstanceState.getInt("BUTTON_VISIBILITY") is underlined red
}

解决方法

正如我刚刚评论的那样,您可以添加@SuppressWarnings(“ResourceType”).希望这可以帮助!

Alt-Enter组合

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...