android support v14 PreferenceFragment crashes

后端 未结 2 1967
借酒劲吻你
借酒劲吻你 2021-01-06 11:13

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

相关标签:
2条回答
  • 2021-01-06 11:44

    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.

    0 讨论(0)
  • 2021-01-06 11:46

    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;
    }
    
    0 讨论(0)
提交回复
热议问题