有没有办法在google maps v2弹出窗口中点击其他活动?
这是我的代码:
@Override
public View getInfoContents(Marker marker)
{
View popup=inflater.inflate(R.layout.popup, null);
final TextView tvtitulo=(TextView)popup.findViewById(R.id.tvTitulo);
TextView tvDatos=(TextView)popup.findViewById(R.id.tvDatos);
TextView tvCat=(TextView)popup.findViewById(R.id.tvCategoria);
tvtitulo.setText(marker.getTitle());
StringTokenizer tokens = new StringTokenizer(marker.getSnippet(), "?");
final String first = tokens.nextToken();// this will contain "Fruit"
String second = tokens.nextToken();// this will contain " they taste good"
tvDatos.setText(first);
tvCat.setText(second);
ImageView imagen = (ImageView)popup.findViewById(R.id.menuImgView);
if(marker.getTitle().substring(0,3).equalsIgnoreCase("Bar"))
imagen.setBackgroundResource(R.drawable.bar);
else if(marker.getTitle().substring(0,3).equalsIgnoreCase("Res"))
imagen.setBackgroundResource(R.drawable.rest);
else
imagen.setVisibility(4);
return(popup);
}
我想在该方法中添加类似的内容:
popup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(), InfoLocal.class);
startActivity(intent);
finish();
}
});
谢谢你的答案,对不起我的英语。
答案 0 :(得分:0)
是的,在这里看看我是如何做到的,你在代码中有评论来了解发生了什么:
// Setting a custom info window adapter for the google map
map.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker args) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker args) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
// Getting the position from the marker
clickMarkerLatLng = args.getPosition();
TextView title = (TextView) v.findViewById(R.id.tvTitle);
title.setText(args.getTitle());
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker)
{
if (SGTasksListAppObj.getInstance().currentUserLocation!=null)
{
if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) &&
String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
{
Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.", Toast.LENGTH_SHORT).show();
}
else
{
FlurryAgent.onEvent("Start navigation window was clicked from daily map");
tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository();
for (Task tmptask : tasksRepository)
{
String tempTaskLat = String.valueOf(tmptask.getLatitude());
String tempTaskLng = String.valueOf(tmptask.getLongtitude());
Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8));
if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
{
task = tmptask;
break;
}
}
Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class);
intent.putExtra(TasksListActivity.KEY_ID, task.getId());
startActivity(intent);
}
}
else
{
Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.", Toast.LENGTH_SHORT).show();
}
}
});
// Returning the view containing InfoWindow contents
return v;
}
});
答案 1 :(得分:0)
是的,但是如果您只是想要使用默认视图进行点击而不提供自己的点击,则只需要:
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker)
{
//do sth with your click
}
});