Android - 用 Butterknife 替换 findViewById

标签 android findviewbyid butterknife

我已成功将 findViewByIds 替换为 Butterknife 库。 不幸的是,出现了一个问题:

final Button btnPopup = (Button) popupView.findViewById(R.id.btn_popup); //popupView.findViewById(...) problem!!!

如何在 Butterknife 中更改这行代码:因为 Butterknife.bind(this); 占用了整个 Activity Views

最佳答案

使用

将您的 popupView 绑定(bind)到您的主视图
View popupView = View.inflate(getContext(), R.layout.yourPopup, null);
ButterKnife.bind(this,popupView);

或者你可能想直接使用

Button btnPopup = ButterKnife.findById(popupView, R.id.btn_popup);

关于Android - 用 Butterknife 替换 findViewById,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45879342/

相关文章:

java - 常见的 AVD 模拟器已在运行错误

java - Android Studio findViewById 在查找 EditText 时抛出错误

android - findViewById错误-没有足够的信息来推断类型变量T。我复制了java代码并在线转换了它

android - ImageView invisible 在 setVisibility() 之后不可见

android - 如何使用 ButterKnife 内部适配器

android - 通过 adb shell 命令打开摄像机

android - 如何在 Android 上的 Glide 中显示数据库图像?

android - java.lang.IllegalStateException : Required view not found - butterknife not working sometimes 错误

android - Butter Knife - 在 Android lib 上注入(inject)

android - Jetpack Compose 中的居中文本