【发布时间】:2014-11-26 03:51:34
【问题描述】:
我正在尝试如下设置按钮的可见性:
public Bundle setActivityState(Bundle bundle){
startBtn = (Button) findViewById(R.id.startSensorsBtn);
startBtn.setVisibility(
getVisibilityState(bundle, PersistanceConstants.START_BTN_STATE)
);
return bundle;
}
public int getVisibilityState(Bundle bundle, String keyName){
if (bundle.getInt(keyName) == View.VISIBLE){
return View.VISIBLE;
} else if (bundle.getInt(keyName) == View.INVISIBLE){
return View.INVISIBLE;
} else if (bundle.getInt(keyName) == View.GONE){
return View.GONE;
}
return 0;
}
但我得到了错误:
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.
打电话时
getVisibilityState(bundle, PersistanceConstants.START_BTN_STATE)
我不知道如何解决这个问题。我知道它需要一组给定的值,但我所知道的只是将int 传递给它。在这里可以做什么?
【问题讨论】:
-
发布您的错误日志..
-
getVisibilityState 到达线
return 0;?请发布您的错误日志。 -
对不起,我没有提到这个。我在 Android Studio 的编译期间得到了这个。
-
将
return 0更改为return View.VISIBLE -
我做到了。它仍然给出同样的错误。