I use DrawerLayout
including 4 pages. I want to create setting
page for my app.
This is MainActivity.class for initializing DrawerLayout
:
public void selectDrawerItem(MenuItem menuItem) {
// Create a new fragment and specify the fragment to show based on nav item clicked
android.support.v4.app.Fragment fragment = new android.support.v4.app.Fragment;
Class fragmentClass;
switch(menuItem.getItemId()) {
case R.id.nav_item_home:
fragmentClass = HomeFragment.class;
break;
case R.id.nav_item_setting:
fragmentClass = SettingFragment.class;
break;
case R.id.nav_item_help:
fragmentClass = HelpFragment.class;
break;
case R.id.nav_item_about:
fragmentClass =AboutFragment.class;
break;
default:
fragmentClass = HomeFragment.class;
break;
} try {
fragment = (android.support.v4.app.Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
This is SettingFragment.class:
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v4.app.Fragment;
public class SettingFragment extends PreferenceFragment {
public SettingFragment(){
}
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
addPreferencesFromResource(R.xml.fragment_settings);
}
}
But as i run and click on setting in drawer layout , nothing shows in setting page.
ence
So, how can I solve it?