1

有没有办法在谷歌地图 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();
        }
    });

谢谢你的回答,对不起我的英语。

4

2 回答 2

1

是的,但如果您只想点击默认视图而不提供您自己的视图,您只需要这个:

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
            public void onInfoWindowClick(Marker marker)
            {
            //do sth with  your  click

            }
        });
于 2015-10-20T21:21:55.957 回答
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;

            }
        });  
于 2013-04-08T10:18:30.653 回答