2015-08-21 13 views
6

Zapisuję i przywracam widoczność widoków w jednym z moich działań. Robię to pod numerem mButton.getVisibility() i zapisuję to w Bundle. W onRestore, gdzie otrzymuję wartość int, pokazuje błąd.Musi być jednym z: 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. 

Kod kompiluje i działa bez żadnych błędów

kodowych

@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 
} 
+2

Możesz dodać '@SuppressWarnings ("ResourceType")' – BNK

+0

Normalnie ostrzeżenie jest podkreślony żółty, to jest podkreślone czerwonym powodując mnie pewne obawy – Eoin

+1

@SuppressWarnings ("ResourceType") pracował! dziękuję – Eoin

Odpowiedz

13

Jak już zauważył, można dodać @SuppressWarnings("ResourceType"). Mam nadzieję że to pomoże!

Alt-Enter enter image description here

+1

Tak, to się stało, dziękuję – Eoin

+0

Moje doświadczenie jest takie, że: gdy AS ostrzega, naciśnij Alt-Enter, aby znaleźć rozwiązanie :) – BNK

+0

Alt-Enter nie miał nic do tego:/ – Eoin

Powiązane problemy