Android的DialogFragment onViewCreated不叫不叫、Android、DialogFragment、onViewCreated

由网友(别来无恙√你还人模狗样)分享简介:我使用的Andr​​oid兼容性库(V4版本8)。在自定义DialogFragment的overrided方法onViewCreated没有得到called.For如:I am using android compatibility library (v4 revision 8). In the custom Dia...

我使用的Andr​​oid兼容性库(V4版本8)。在自定义DialogFragment的overrided方法onViewCreated没有得到called.For如:

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中,包)后立即调用返回。

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).

阅读全文

相关推荐

最新文章