获取上下文中的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.
上一篇:SQLiteDatabase getWritableDatabase(){抛出新的RuntimeException("存根"!); }存根、抛出、getWritableDataba