Must be one of: View.VISIBLE, View.INVISIBLE, View.GONE

I maintain and restore the appearance of views in one of my actions. I do this by calling mButton.getVisibility() and storing it in the Bundle . In onRestore, where I get the int value, it shows an error.

 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. 

The code compiles and runs without errors

code

 @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 } 
+6
source share
1 answer

As I just commented, you can add @SuppressWarnings("ResourceType") . Hope this helps!

Alt-enter enter image description here

+13
source

All Articles