0

I am trying to a make custom InfoWindow in which I have a button and TextView, but that button is not working, when I click on it, the whole infoWindow is clicked. this is the my onReadyMap function:

public void onMapReady(GoogleMap map) {
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, 123);
    }
   else{

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
       // Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if(location==null)
        {
            Toast.makeText(this,"erreur de connexion",Toast.LENGTH_SHORT);
        }
    if (location != null)
    {   map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            View v = getLayoutInflater().inflate(R.layout.info_window,null);
            TextView nomCompagnie = (TextView) v.findViewById(R.id.txt_infoWindow_compagnie);
            TextView assurance = (TextView) v.findViewById(R.id.txt_infoWindow_assurance);
            TextView dispo = (TextView) v.findViewById(R.id.txt_infoWindow_dispo);
            TextView loca = (TextView) v.findViewById(R.id.txt_infoWindow_localisation);
            Button notifier = (Button) v.findViewById(R.id.btn_infowindow_notif);
            nomCompagnie.setText(marker.getTitle());
            LatLng latlng=marker.getPosition();
            loca.setText("("+latlng.latitude+","+latlng.longitude+")");

            return v;
        }
    });
        map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                Toast.makeText(getApplicationContext(),"clicked",Toast.LENGTH_SHORT).show();
                return false;
            }
        });
        map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
        map.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Je suis ici !")).showInfoWindow();
        for(int i=0;i<arrayPosition.size();i++)
        {
            map.addMarker(new MarkerOptions().position(new LatLng(arrayPosition.get(i).getLatitude(), arrayPosition.get(i).getLongitude())).title("Je suis numéro "+i+"")).showInfoWindow();
           // Log.d("wiwwww", "heereee");
        }
       CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(location.getLatitude(), location.getLongitude()))      // Sets the center of the map to location user
                .zoom(12)                   // Sets the zoom
                .build();                   // Creates a CameraPosition from the builder
        map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        map.setMyLocationEnabled(true);

    }}}

Does anyone have any idea can make only the button clickable? enter image description here

  • 1
    This is perfectly normal. Unless something significant changed with Maps V2 when I was not looking, what you are seeing on the screen is not the `View` of your info window, but a `Bitmap` generated from that `View`. Interactive contents of an info window are not supported. – CommonsWare Dec 09 '16 at 19:08

1 Answers1

1

I think here is what you are looking for .Moreover you can use this library to do what you want .

Community
  • 1
  • 1
Mithun Sarker Shuvro
  • 3,902
  • 6
  • 32
  • 64