Sto salvando e ripristinando la visibilità di una vista in una delle mie attività. Faccio questo chiamando mButton.getVisibility()
e salvando questo in un Bundle
. In onRestore, dove ottengo il valore int, mostra un errore.Deve essere uno di: View.VISIBLE, View.INVISIBLE, View.GONE
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.
Il codice compilato ed eseguito senza errori
codice
@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
}
È possibile aggiungere '@SuppressWarnings ("ResourceType")' – BNK
Normalmente un avviso viene sottolineata giallo, questo è sottolineato rosso mi ha causato qualche preoccupazione – Eoin
@SuppressWarnings ("ResourceType") ha funzionato! grazie – Eoin