加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 无法动态设置setVisibility()参数

发布时间:2020-12-14 16:44:25 所属栏目:Java 来源:网络整理
导读:我正在设置一个按钮的可见性,如下所示: public Bundle setActivityState(Bundle bundle){ startBtn = (Button) findViewById(R.id.startSensorsBtn); startBtn.setVisibility( getVisibilityState(bundle,PersistanceConstants.START_BTN_STATE) ); return
我正在设置一个按钮的可见性,如下所示:
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.这里可以做些什么?

解决方法

当你知道你在做什么,你可以在本地禁止这个Android Studio检查
//noinspection ResourceType

例如,

//noinspection ResourceType
startBtn.setVisibility(bundle.getInt(PersistanceConstants.START_BTN_STATE));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读