如何从内部类返回值? [英] How to return a value from a inner class?

查看:104
本文介绍了如何从内部类返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在这里:

public static boolean showConfirmationDialog(Context context, String title, String dialogContent) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(title);
        builder.setMessage(dialogContent);
        builder.setPositiveButton("Confirm", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // what to do ?
            }
        });

现在,我想点击确认按钮后返回true。那么如何从内部类返回true - 方法的OnClickListener。

right now, I want to return true after I clicked the "confirm" button. so how do I return "true" from a inner class - OnClickListener for the method.

需要一些帮助,谢谢。

推荐答案

在此实例中,您无法从内部类返回内容。在这种情况下,它没有多大意义。该程序应该在你的onClick函数内等待,直到它返回一些东西?这并不是听众的工作方式。如果返回true,你需要做的就是执行你计划执行的任何代码,并把它放在你的内部类中。

You can't return things from an inner class in this instance. In this case it doesn't make much sense. Is the program supposed to wait inside your onClick function until it returns something? That's not really how listeners work. What you need to do is take what ever code you plan on executing if "true" was returned, and put it inside your inner class.

这篇关于如何从内部类返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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