android support v14 PreferenceFragment crashes

后端 未结 2 1966
借酒劲吻你
借酒劲吻你 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: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;
    }
    

提交回复
热议问题