android - 必须是 : View. VISIBLE、View.INVISIBLE、View.GONE 之一

标签 android android-view

<分区>

我正在保存和恢复我的一项 Activity 中的 View 可见性。我通过调用 mButton.getVisibility() 并将其保存在 Bundle 中来完成此操作。在我获取 int 值的 onRestore 中,它显示错误。

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 enter image description here

关于android - 必须是 : View. VISIBLE、View.INVISIBLE、View.GONE 之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131417/

相关文章:

android - 如何让一个View填满剩余的空间?

android - 在 View 上应用 Fling 和 ACTION_MOVE

java - 关闭 Android 应用程序一段时间

android - 如何在android中制作自定义罗盘 View

android - 构建 AOSP 5.1 时出现 API 更改错误

java - 将数据传递给另一个类

java - 如何从 android TimeSquare 库中获取选定的日期?

android - 有多少个 WindowInsets?

java - 如何修复 EditText 的 getText 方法的重写

java - 如何消除 Y 轴(MPAndroidChart)中的重复数字?