为什么在我的自定义对话框片段中没有调用onShow? [英] Why isn't onShow in my custom dialogfragment being invoked?

查看:126
本文介绍了为什么在我的自定义对话框片段中没有调用onShow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的alertdialog,它实现了接口,以便可以调用它们的回调.

I have a custom alertdialog that implements interfaces so that their callbacks can be invoked.

我在onDismiss和onShow的第一行中设置了断点.

I set breakpoints in the first lines of onDismiss and onShow.

对话框弹出,我看到了所有视图,但是onShow中的断点未命中,并且我的异步任务也未创建.

The dialog pops up and I see all the views, but the breakpoint in onShow does not get hit and my async task does not get created.

public class CountdownDialogFragment extends DialogFragment 
implements OnClickListener, OnShowListener, OnDismissListener {
    InnerClassAsyncTask myAsyncTask;

@Override public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        builder.setTitle("Countdown");
        builder.setMessage("The final countdown...");

        builder.setNegativeButton("Cancel", this);
        builder.setPositiveButton(getResources().getString("Start", this);

        builder.setView(view);

        return builder.create();
    }
    @Override public void onDismiss(final DialogInterface dialog) {
        myAsyncTask.cancel(true);
    }

    public void setDialogOnClickListener(OnClickListener  
                                     dialogOnClickListener) {
        clickListener = dialogOnClickListener;
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if(clickListener != null) {
            clickListener.onClick(dialog, which);
        }
    }

    @Override
    public void onShow(DialogInterface dialog) {
        myAsyncTask = new InnerClassAsyncTask();
        myAsyncTask.execute();
    }

    private static class InnerClassAsyncTask extends AsyncTask<Void,    
                                                     Integer, Void> {
    // ...updates a determinate progressbar in this alert dialog
    }

在我的调用片段中,我通过newInstance实例化此对话框,并通过以下方式显示它:

In my calling fragment I instantiate this dialog via newInstance and show it via:

myCountdownDialog.show();

推荐答案

在onCreateDialog中,我忘记设置侦听器:dialogObj.setOnShowListener(this).

in onCreateDialog, I forgot to set the listener: dialogObj.setOnShowListener(this).

这篇关于为什么在我的自定义对话框片段中没有调用onShow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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