0
我在我的活動中有三個片段。我正在使用Recyclerview
來顯示它們。我想對我的片段進行分組,例如在導航抽屜中選擇A時,片段1和2將使用viewpager顯示。這工作正常。從導航抽屜中選擇時不顯示片段
但是,當我選擇片段B它不顯示。片段B不在分組中。
請幫我一把。
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{
Toolbar toolbar;
SharedPreferences savedPreferences;
private static Context mContext;
private FragmentDrawer drawerFragment;
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle("");
toolbar.setSubtitle("");
setSupportActionBar(toolbar);
}
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
drawerFragment.setDrawerListener(this);
displayView(0);
}
@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new TabFragment();
break;
case 1:
fragment = new MoviesFragment();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
}
}}
在這種情況下,MoviesFragment
不顯示。當我從導航抽屜中選擇MoviesFragment時,只會出現一個空白的白色屏幕。
謝謝!