必须是以下之一:View.VISIBLE、View.INVISIBLE、View.GONE
Must be one of: View.VISIBLE, View.INVISIBLE, View.GONE
我正在保存和恢复我的一项活动中的视图可见性。我通过调用 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
我正在保存和恢复我的一项活动中的视图可见性。我通过调用 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