【发布时间】:2015-12-17 22:28:56
【问题描述】:
我的 Activity 已扩展到 AppCompatActivity。我也成功设置了一个抽屉。现在,当我在 Fragment 上进行交易时,它基本上使用 begintransaction。但我在android.app.FragmentManager fragmentManager = getFragmentManager(); 上收到此错误消息Unreachable statement,我还尝试了 android.support.v4.app 包它也说这是不推荐使用的。
在我的抽屉导航onClickListener
我有这个
`
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
android.app.Fragment objFragment = null;
menuItem.setChecked(true);
switch (menuItem.getItemId()) {
case R.id.dhome:
objFragment = new panel();
mCurrentSelectedPosition = 0;
return true;
case R.id.dsetting:
mCurrentSelectedPosition = 1;
return true;
case R.id.dlogout:
mCurrentSelectedPosition = 2;
return true;
default:
return true;
}
// update the main content by replacing fragments
if(objFragment != null) {
android.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, objFragment)
.commit();
}
}
});`
在我的布局中
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
>
<FrameLayout android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#d9d8d8"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
标签: java android switch-statement fragment