使用自定义对话框时无法使用onDismiss() - Android [英] Can't use onDismiss() when using custom dialogs - Android

查看:125
本文介绍了使用自定义对话框时无法使用onDismiss() - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小程序,我需要添加一个自定义对话框,在关闭时将一些信息传递给调用活动。
我扩展了对话框类,当我尝试捕获自定义对话框关闭时,使用onDismiss侦听器,它从来没有达到它,因为我使用一个自定义对话框。



这是我活动的一部分 -

 


属性customizeDialog =新属性(con,position,pick.getLastVisiblePosition());
customizeDialog.show();

(属性是扩展对话框类的类的名称)



这是我在对话框完成时设置的事件监听器 -

  customizeDialog.setOnDismissListener (new DialogInterface.OnDismissListener(){

@Override
public void onDismiss(DialogInterface dialog){
Log.v(LOG_CAT,attributes.selectedIndexes.get(0) ++ attributes.selectedIndexes.get(1)++ attributes.selectedIndexes.get(2)++ attributes.selectedIndexes.get(3)++ attributes.selectedIndexes.get(5)+ );
}

});

我知道我做错了,我只是不知道如何解决它。 / p>

我真的很感谢任何帮助这个问题。



谢谢!

解决方案

我倾向于让我的活动实现这样的听众...

  public class MyActivity extends Activity 
implements DialogInterface.OnDismissListener {

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)

属性customizeDialog =新属性(con,position,pick.getLastVisiblePosition());
customizeDialog.setOnDismissListener(this);
customizeDialog.show();
}

@Override
public void onDismiss(DialogInterface dialog){
// do whatever
}
}


I'm working on a little program, and I need to add a custom dialog that passes some info to the calling acitivity when it closes. I extended the dialog class, and when I try to capture the custom dialog when it closes,using an onDismiss listener, it never reaches it because I used a custom dialog.

This is part of my activity -

    .
    .
    .
       attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
        customizeDialog.show();

(The attributes being the name of the class that extends the dialog class).

Here is the event listener I set up when the dialog finishes -

    customizeDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Log.v("LOG_CAT",attributes.selectedIndexes.get(0) + " " + attributes.selectedIndexes.get(1) + " " + attributes.selectedIndexes.get(2) + " " + attributes.selectedIndexes.get(3) + " " + attributes.selectedIndexes.get(5) + " ");
    }

});

I know i'm doing it wrong,I just don't know how to fix it.

I would really appreciate any help with this problem.

Thanks!

解决方案

I tend to have my activity implement listeners like this...

public class MyActivity extends Activity
    implements DialogInterface.OnDismissListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
        customizeDialog.setOnDismissListener(this);
        customizeDialog.show();
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        // Do whatever
    }
}

这篇关于使用自定义对话框时无法使用onDismiss() - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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