安卓:startActivity()从AlertDialog [英] Android: startActivity() from AlertDialog
问题描述
我想使用在AlertDialog一个按钮来查看的网页。
I am trying to use a Button in an AlertDialog to view a webpage.
问题是,这AlertDialog位于延伸ItemizedOverlay和不活动扩展一个类里面,所以Eclipse中强调,并提供了以下错误:
The problem is that this AlertDialog is located inside a class that extends ItemizedOverlay and doesn't extend Activity, so Eclipse underlines it and gives the following error:
该方法startActivity()是未定义的类型新DialogInterface.OnClickListener(){}
The method startActivity() is undefined for the type new DialogInterface.OnClickListener(){}
我想从PositiveButton,NeutralButton和NegativeButton开展活动,但我不能。
I would like to launch activities from the PositiveButton, NeutralButton and NegativeButton, but I am not able to.
如果你需要更多的背景下,主要活动是与一些ItemizedOverlay一个图形页面,我想用发射方向上的网页或者做另一个活动。
In case you need more context, the main Activity is a MapView with some ItemizedOverlay, and I would like to launch a webpage with directions or another activity that does that.
推荐答案
在其中包含与上下文
对象作为参数快讯类构造一个构造函数。它分配给一个上下文变量。
Construct a constructor in the class which contains your alert with Context
object as a parameter. Assign it to a Context variable.
使用上下文变量创建的意图。
Use this context variable for creating the intent.
Intent intent = new Intent(mContext, "Your next activity to be shown");//mContext is the Context variable over here.
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
这篇关于安卓:startActivity()从AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!