Android 如何将不同的布局与Butterknife一起用于BaseActivityClass和ActivityExtension?
我想使用Butterknife,但也要在BaseActivityClass中创建和维护抽屉逻辑,该BaseActivityClass由具有不同LayoutId的所有其他活动扩展 尝试通过抽象方法提供LayoutId并手动将其膨胀,但Butterknife失败并出现错误:Android 如何将不同的布局与Butterknife一起用于BaseActivityClass和ActivityExtension?,android,butterknife,Android,Butterknife,我想使用Butterknife,但也要在BaseActivityClass中创建和维护抽屉逻辑,该BaseActivityClass由具有不同LayoutId的所有其他活动扩展 尝试通过抽象方法提供LayoutId并手动将其膨胀,但Butterknife失败并出现错误: Caused by: java.lang.IllegalStateException: Required view 'View' with ID 2131493000 for field 'mView' was not foun
Caused by: java.lang.IllegalStateException: Required view 'View' with ID 2131493000 for field 'mView' was not found. If this view is optional add '@Nullable' annotation.
基类
@Bind(R.id.leftDrawer)
protected ListView mLeftDrawer;
@Bind(R.id.drawerLayout)
protected DrawerLayout mDrawerLayout;
@Bind(R.id.contentFrame)
protected FrameLayout mContentFrame;
private ActionBarDrawerToggle drawerToggle;
protected abstract @LayoutRes int getContentLayout();
private Intents mIntents;
private String[] mOptionsTitles = new String[]{
"Menu item 1",
"Menu item 2",
"Menu item 3"
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_activity);
getLayoutInflater().inflate(getContentLayout(), mContentFrame);
ButterKnife.bind(this);
}
活动课
@Override
protected int getContentLayout() {
return R.layout.activity_main;
}
目前,我只剩下一个选项,即所有活动中抽屉处理的重复逻辑。
这两个选项都希望避免。如果没有butterknife,它可以工作吗?是的,如果我在扩展类中通过butterknife放弃绑定,并在基类中使用:GetLayoutFlater().充气(getContentLayout(),McContentFrame),则没有问题。当我尝试在扩展类中使用Butterknife而不是findById时,Butterknife抛出。我对Butterknife在布局中使用“include”有一个问题。这帮助了我:。如果没有butterknife,它可以工作?是的,如果我在扩展类中通过butterknife放弃绑定,并在基类中使用:GetLayoutFlater().充气(getContentLayout(),McContentFrame),那么就没有问题了。当我尝试在扩展类中使用Butterknife而不是findById时,Butterknife抛出。我对Butterknife在布局中使用“include”有一个问题。这对我有帮助。