I added a button to InfoWindow, but nothing happens when I click it.

Tell me what's wrong. Even System.out.println does not display.

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(final Marker marker) { View v = getActivity().getLayoutInflater().inflate(R.layout.window_info_map, null); TextView text = (TextView)v.findViewById(R.id.titleMarker); Button del = (Button)v.findViewById(R.id.imgDelMarker); text.setText(dbHelperMap.getMarker(marker.getPosition().latitude, marker.getPosition().longitude).getName()); del.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); for (com.pineapple.softgroup.DB.model.Marker mark : markersList) { if (mark.getLatitude() == marker.getPosition().latitude && mark.getLongitude() == marker.getPosition().longitude) { System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); dbHelperMap.deleteMarker(mark); Toast.makeText(getActivity(), "delete", Toast.LENGTH_LONG).show(); } } } }); return v; } @Override public View getInfoContents(final Marker marker) { LinearLayout layout = new LinearLayout(mapFragment.getActivity()); Button btn = new Button(mapFragment.getActivity()); layout.addView(btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); for (com.pineapple.softgroup.DB.model.Marker mark : markersList) { if (mark.getLatitude() == marker.getPosition().latitude && mark.getLongitude() == marker.getPosition().longitude) { System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); dbHelperMap.deleteMarker(mark); Toast.makeText(getActivity(), "delete", Toast.LENGTH_LONG).show(); } } } }); return layout; } }); 

    1 answer 1

    I don't know what's in the latest maps, but it seems like when you add an InfoWindow marker, the views are not clickable there, you can catch only a click on the whole InfoWindow and that's it.

    Therefore, there are two solutions to the problem:
    1 - catch click on the whole InfoWindow
    2 - to catch a click on the marker, on which to position your view, which was intended for InfoWindow , on top of the map, and when you move the map, you have to set setX()/setY() moving this view setX()/setY() .

    In the second case, individual elements can be clickable, but you have to control the handles, when to show, when to hide and when to move.