I'm developing an app that uses DrawerLayout
. The opening of each menu item is done according to the code below:
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
...
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
//Abre o primeiro item
break;
case 1:
//Abre o segundo item
break;
case 2:
//Abre o terceiro item
break;
case 3:
fragment = new ConfiguracoesFragment();
title = getString(R.string.title_configuracoes);
break;
case 4:
title = getString(R.string.title_desconectar);
startActivity(new Intent(this, InicialActivity.class));
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
getSupportActionBar().setTitle(title);
}
}
}
Each menu item is a class that extends from android.support.v4.app.Fragment
. The ConfiguracoesFragment file also extends from the same class. To use PreferenceFragment
, I should extend it from android.app.Fragment
, that is, it is not possible to make substitution in fragmentTransaction.replace(R.id.container_body, fragment)
because PreferenceFragment
does not extend from the same base class.
How to load a class that extends PreferenceFragment into a DrawerLayout?