Problem inflating custom view for AlertDialog in DialogFragment

后端 未结 9 2424
忘了有多久
忘了有多久 2020-11-27 04:43

I\'m trying to create a DialogFragment using a custom view in an AlertDialog. This view must be inflated from xml. In my DialogFragment

9条回答
  •  鱼传尺愫
    2020-11-27 05:03

    I had the same problem. In my case it was becasue Android Studio created a template onCreateView that re-inflated a new view instead of returning the view created in onCreateDialog. onCreateView is called after onCreateDialog, so the solution was to simply reurnt the fragments view.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return this.getView();
    }
    

提交回复
热议问题