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
}
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.
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.
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.
try that setVisible(0) to visible true . and setVisible(4) to visible false. the text can be invisible but the button and datepicker no.
As I have just commented, you can add @SuppressWarnings("ResourceType")
. Hope this helps!
Alt-Enter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With