我希望在所有活動中使用導航抽屜。因此,我使用了BaseActivity作爲導航抽屜並從基本活動中擴展了其他活動.Base活動具有導航抽屜。儀表盤活動延伸基地活動,但它會引發異常,當我嘗試使用butterknife綁定的觀點說
Android:在活動中使用ButterKnife從其他活動延伸
java.lang.IllegalStateException: Required view 'dashboard_frameLayout' with ID 2131558517 for field 'frameLayout' was not found.
這裏有相關的文件
BaseActivity.java
public class BaseActivity extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
ButterKnife.bind(this);
//set toolbar and both Navigation Drawer
}
DashboardActivity.java
public class DashBoardActivity extends BaseActivity {
@BindView(R.id.dashboard_frameLayout)
FrameLayout frameLayout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = getLayoutInflater().inflate(R.layout.activity_dashboard,frameLayout);
ButterKnife.bind(this,view);
init();
}
private void init() {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dashboard_frameLayout);
if(fragment != null){
Utils.getInstance().addFragment(this,new Fragment_Dashboard(),R.id.dashboard_frameLayout);
}
}
}
activity_dashboard.xml
<FrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboard_frameLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
爲什麼在儀表板活動中未找到framelayout?
正確讀取的問題。它不是關於fragment.Its關於framelayout,它出現在activity_dashboard.xml中,即使在綁定視圖後也是null。 –
和你的活動佈局應該有一個工具欄和一個容器內的FrameLayout定義。我沒有看到它的工具欄。 – Nicholas
如果我使用的setContentView(R.layout.activity_dashboard)在subclass.It將覆蓋layout.I不會得到這個activit.y –