问题描述
我使用的Android兼容性库(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).
这篇关于Android的DialogFragment onViewCreated不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!