无法动态设置setVisibility()参数

我试图按如下所示设置按钮的可见性:

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给它。在这里可以做什么?

回答:

当您知道自己在做什么时,可以使用

//noinspection ResourceType

例如,

//noinspection ResourceType

startBtn.setVisibility(bundle.getInt(PersistanceConstants.START_BTN_STATE));

以上是 无法动态设置setVisibility()参数 的全部内容, 来源链接: utcz.com/qa/402917.html

回到顶部