Android的:如何从一个警告对话框启动活动 [英] Android: How to start an Activity from an alert dialog

查看:141
本文介绍了Android的:如何从一个警告对话框启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要当用户选择在警告对话框中的项目启动活动。我如何获得上下文传递给意向构造以下code ...

I need to start an activity when the user chooses an item in an alert dialog. How do I get the context to pass to the intent constructor in the following code...

builder.setItems(items, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {

                Intent i = new Intent(<WHAT DO I PUT HERE?>, <new activity>.class);    
                startActivity(i);

      }

});

它是采用内部类的?有什么想法?

Is it the use of the inner class?? Any thoughts?

推荐答案

您可以检索你传递给 AlertDialog.Builder getBaseContext上下文()。 查看文档<一href="http://developer.android.com/reference/android/content/ContextWrapper.html#getBaseContext%28%29">here.

You can retrieve the context you have passed to AlertDialog.Builder with getBaseContext(). See the doc here.

所以,这应该工作:

Intent i = new Intent(getBaseContext(), <new activity>.class);    
startActivity(i);

这篇关于Android的:如何从一个警告对话框启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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