必须是以下之一:View.VISIBLE,View.INVISIBLE,View.GONE

时间:2015-08-21 02:21:51

标签: android android-view

我正在保存并恢复其中一项活动的观看次数。我这样做是通过致电mButton.getVisibility()并将其保存在Bundle中。在onRestore中,我得到了int值,它显示错误。

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.

代码编译并运行,没有错误

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

1 个答案:

答案 0 :(得分:13)

正如我刚刚评论的那样,您可以添加YourScrollContainerNameHere.horizontalScrollPolicy = Scroller.SCROLL_POLICY_OFF; YourScrollContainerNameHere.verticalScrollPolicy = Scroller.SCROLL_POLICY_AUTO; 。希望这有帮助!

Alt-Enter组合 enter image description here