我使用DrawerLayout
包括4页。我想为我的应用创建setting
页面。
这是MainActivity.class,用于初始化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();
}
这是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);
}
}
但是当我跑步并点击抽屉布局中的设置时,设置页面中没有任何内容。
EnCE的
那么,我该如何解决呢?