I\'m trying to display settings in an Android app using a PreferenceFragment from the android.support.v14.preference
library. However, when I try to open the pr
Comment out your onCreateView()
method.
Or, chain to the superclass implementation of onCreateView()
and embed its response in your own wrapper, if for some reason you want additional stuff around the stock PreferenceFragment
UI.
PreferenceFragment
probably is expecting its onCreateView()
to create the RecyclerView
that is missing per your stack trace.
A PreferenceFragment
already inflates the appropriate layout for use - by using your own R.layout.fragment_settings
, it isn't able to find the appropriate views it requires.
If you'd like to modify the RecyclerView
itself, consider overriding onCreateRecyclerView(). If instead you want to create some custom framing around the default layout, you can use a pattern such as:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_settings, container, false);
// The frame you want to embed the parent layout in.
final ViewGroup innerContainer = (ViewGroup) view.findViewById(R.id.main_frame);
final View innerView = super.onCreateView(inflater, innerContainer, savedInstanceState);
if (innerView != null) {
innerContainer.addView(innerView);
}
return view;
}