Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Must be one of: View.VISIBLE, View.INVISIBLE, View.GONE [duplicate]

I am saving and restoring a views visibility in one of my activities. I do this by calling mButton.getVisibility() and saving this in a Bundle. In onRestore where I get the int value it is showing 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 with no 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
}
like image 887
Eoin Avatar asked Aug 21 '15 02:08

Eoin


People also ask

What is the difference between VIEW gone and view invisible?

GONE This view is invisible, and it doesn't take any space for layout purposes. View. INVISIBLE This view is invisible, but it still takes up space for layout purposes.

What is setVisibility?

This transition tracks changes to the visibility of target views in the start and end scenes. Visibility is determined not just by the View#setVisibility(int) state of views, but also whether views exist in the current view hierarchy.

What is the difference between invisible and gone for the view visibility status?

INVISIBLE: This view is invisible, but it still takes up space for layout purposes. GONE: This view is invisible, and it doesn't take any space for layout purposes.

How do you change the visibility of a view?

try that setVisible(0) to visible true . and setVisible(4) to visible false. the text can be invisible but the button and datepicker no.


1 Answers

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

Alt-Enter enter image description here

like image 177
BNK Avatar answered Nov 02 '22 22:11

BNK