我想要一个类似以下的代码将PreferenceFragment
加载到Fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int inx = getArguments().getInt("index", 0);
View view;
switch (inx){
case 0:
view = inflater.inflate(R.layout.a, container, false);
break;
case 1:
view = inflater.inflate(R.layout.b, container, false);
break;
case 2:
view = MyPreferenceFragment();
break;
default:
view = inflater.inflate(R.layout.a, container, false);
}
return view;
}
答案 0 :(得分:0)
尝试将以下内容添加到案例2中:
getFragmentManager().beginTransaction().replace(android.R.id.content,new {YourSettingsClass} ()).commit();
并在活动布局中声明片段。
查看此信息以获取更多信息How to Load PreferenceFragment in Fragment