获取上下文中的onClick(DialogInterface V,诠释buttonId)? [英] Get context inside onClick(DialogInterface v, int buttonId)?

查看:106
本文介绍了获取上下文中的onClick(DialogInterface V,诠释buttonId)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取上下文中的onClick(视图中查看),回调的按钮的OnClickListener很简单:

Getting context inside onClick(View view), the callback for a button's OnClickListener is easy:

  view.getContext()

但我想不出如何获取上下文中的onClick(DialogInterface V,诠释buttonId),回调的对话框的OnClickListener:

But I can't figure out how to get context inside onClick(DialogInterface v, int buttonId), the callback for a dialog's OnClickListener:

public class MainActivity extends Activity implements android.content.DialogInterface.OnClickListener

是否有可能呢?

Is it possible at all?

推荐答案

您可以参考的外部环境,当你定义你的 DialogInterface.OnClickListener 作为一个匿名类。如果你在一个活动中,你可以使用 MyActivity.this 作为背景。

You can reference an outer context when you define your DialogInterface.OnClickListener as an anonymous class. If you're in an activity you can use MyActivity.this as the context.

修改 - 因为你的活动是实施 DialogInterface.OnClickListener ,你应该能够只使用这个作为背景。

Edit - since your Activity is implementing DialogInterface.OnClickListener, you should be able to just use this as the context.

这篇关于获取上下文中的onClick(DialogInterface V,诠释buttonId)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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