Android DialogFragment onViewCreated 未调用 [英] Android DialogFragment onViewCreated not called

查看:46
本文介绍了Android DialogFragment onViewCreated 未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android 兼容性库(v4 修订版 8).在自定义 DialogFragment 中,未调用 onViewCreated 覆盖的方法.例如.

I am using android compatibility library (v4 revision 8). In the custom DialogFragment the overrided method onViewCreated is not getting called.For eg.

public class MyDialogFragment extends DialogFragment{
    private String mMessage;
    public MyDialogFragment(String message) {
        mMessage = message;
    }

    @Override
    public Dialog onCreateDialog( Bundle savedInstanceState){
        super.onCreateDialog(savedInstanceState);
        Log.d("TAG", "onCreateDialog");
        setRetainInstance(true); 
        //....do something
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        Log.d("TAG", "onViewCreated");
        //...do something
    }
}

onViewCreated 没有被记录.

onViewCreated is not getting logged.

推荐答案

好吧,onViewCreated 状态的文档在 onCreateView(LayoutInflater, ViewGroup, Bundle) 返回后立即调用".

Well, the docs for onViewCreated state "Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned".

DialogFragment 使用 onCreateDialog 而不是 onCreateView,因此不会触发 onViewCreated.(这应该是我的工作理论,我还没有深入研究 android 源代码来确认).

DialogFragment uses onCreateDialog and not onCreateView, so onViewCreated is not fired. (Would be my working theory, I haven't dived into the android source to confirm).

这篇关于Android DialogFragment onViewCreated 未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆