我正在尝试获取一个将ItemizedOverlay扩展到startActivity的类,但是有一个问题,它就是不能编译。我有一个使用ItemizedOverlay类绘制覆盖图的MapView,但我想要在点击屏幕时启动和活动。
你知道怎么解决这个问题吗?谢谢
protected boolean onTap(int index) {
OverlayItem item = overlays.get(index);
String split_items = item.getSnippet();
Intent intent = new Intent();
intent.setClass(mainmenu,poiview.class);
startActivity(intent);
return true;
}发布于 2011-07-07 01:23:22
我遇到了这个问题,所以我测试了下面的例子。该解决方案依赖于从MapActivity上下文调用"startActivity“。
如果您的地图实际上正在处理覆盖,那么您已经将MapView上下文传递给了自定义ItemizedOverlay构造函数,并且可能将MapView上下文分配给了一个名为mContext的类变量(我假设您遵循了谷歌的MapView示例)。因此,在自定义Overlay的onTap函数中,执行以下操作:
@Override
protected boolean onTap(int index) {
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
mContext.startActivity(intent);
return true;
} 但是,您可能希望将某些内容传递给您正在尝试启动的新活动,以便您的新活动可以对您的选择执行一些有用的操作。所以..。
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
//assumption: you decided to store an "id" in the snippet so you can associate this map location with your new Activity
long id = Long.parseLong(item.getSnippet()); //Snippet is a built-in String property of an Overlay object.
//pass an "id" to the class so you can query
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
String action = Intent.ACTION_PICK; //You can substitute with any action that is relevant to the class you are calling
//I create a URI this way because I append the id to the end of the URI (lookup the NotePad example for help because there are many ways to build a URI)
Uri uri = ContentUris.withAppendedId(Your_CONTENT_URI, id);
//set the action and data for this Intent
intent.setAction(action);
intent.setData(uri);
//call the class
mContext.startActivity(intent);
return true;
}发布于 2012-04-19 16:50:05
试试这个,我已经在警告对话框中设置了一个肯定按钮...
protected boolean onTap(int index) {
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setIcon(R.drawable.info_icon);
dialog.setPositiveButton("Details", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent placeDetailsMapIntent = new Intent(mContext, PlaceDetailsActivity.class);
mContext.startActivity(placeDetailsMapIntent);
}});
发布于 2011-01-02 13:12:52
试着使用下面的
Intent intent = new Intent(mainmenu.this, poview.class);
startActivity(intent);https://stackoverflow.com/questions/4577043
复制相似问题