ClickListener event for custom InfoWindow returns the same value for all markers.












0














the code runs good without errors however the click event for the custom infowindow returns the same value (toast message) for both marker,i need the custom Infowindows to return the specific toast message within when clicked.



code:



public class HotelActivity extends FragmentActivity implements OnMapReadyCallback {



private GoogleMap mMap;
private final static int MY_PERMISSION_FINE_LOCATION = 101;

public static final String Hotdetails = "com.myaddress.Hotdetails";

@Override
public Resources getResources(){
return super.getResources();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hotel);

// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){// ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

LatLng location1 = new LatLng(9.0454, 7.4797);
LatLng location2 = new LatLng(9.036190, 7.480130);

//for location1

Marker ClassMark = mMap.addMarker(new MarkerOptions().position(eclass).title("E-Class Resorts").snippet("3 star resort of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.eclasses)));

InfoWindowData Classinfo = new InfoWindowData();
Classinfo.setImage(("eclass"));
Classinfo.setRatings("the very best");

CustomInfoWindowGoogleMap ClassInfoWindow = new CustomInfoWindowGoogleMap(this);
mMap.setInfoWindowAdapter(ClassInfoWindow);
ClassMark.setTag(Classinfo);

mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {

Toast.makeText(getApplicationContext(), "This is E-class", Toast.LENGTH_LONG).show();
}
});

//for Location2

Marker StateMark = mMap.addMarker(new MarkerOptions().position(Statement).title("Statement HOTEL").snippet("5 star hotel of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.statementes)));

InfoWindowData stateinfo = new InfoWindowData();
stateinfo.setImage(("allstates"));
stateinfo.setRatings("quite nice");

CustomInfoWindowGoogleMap stateInfoWindow = new CustomInfoWindowGoogleMap(this);
mMap.setInfoWindowAdapter(stateInfoWindow);

StateMark.setTag(stateinfo);

mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {

Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();


}
});

mMap.setMyLocationEnabled(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(4.0f));
//mMap.animateCamera(CameraUpdateFactory.zoomIn());
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMinZoomPreference(4.0f);
mMap.setMaxZoomPreference(17.0f);
//mMap.resetMinMaxZoomPreference();

} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
}
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case MY_PERMISSION_FINE_LOCATION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ //&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

mMap.setMyLocationEnabled(true);
//mMap.animateCamera(CameraUpdateFactory.zoomTo(13.0f));
mMap.moveCamera(CameraUpdateFactory.zoomTo(14.0f));
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMinZoomPreference(8.0f);
mMap.setMaxZoomPreference(17.0f);
}

} else {
Toast.makeText(getApplicationContext(), "This service requires location permissions to be granted", Toast.LENGTH_LONG).show();

}
break;
}
}

}









share|improve this question



























    0














    the code runs good without errors however the click event for the custom infowindow returns the same value (toast message) for both marker,i need the custom Infowindows to return the specific toast message within when clicked.



    code:



    public class HotelActivity extends FragmentActivity implements OnMapReadyCallback {



    private GoogleMap mMap;
    private final static int MY_PERMISSION_FINE_LOCATION = 101;

    public static final String Hotdetails = "com.myaddress.Hotdetails";

    @Override
    public Resources getResources(){
    return super.getResources();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hotel);

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
    .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){// ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

    LatLng location1 = new LatLng(9.0454, 7.4797);
    LatLng location2 = new LatLng(9.036190, 7.480130);

    //for location1

    Marker ClassMark = mMap.addMarker(new MarkerOptions().position(eclass).title("E-Class Resorts").snippet("3 star resort of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.eclasses)));

    InfoWindowData Classinfo = new InfoWindowData();
    Classinfo.setImage(("eclass"));
    Classinfo.setRatings("the very best");

    CustomInfoWindowGoogleMap ClassInfoWindow = new CustomInfoWindowGoogleMap(this);
    mMap.setInfoWindowAdapter(ClassInfoWindow);
    ClassMark.setTag(Classinfo);

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {

    Toast.makeText(getApplicationContext(), "This is E-class", Toast.LENGTH_LONG).show();
    }
    });

    //for Location2

    Marker StateMark = mMap.addMarker(new MarkerOptions().position(Statement).title("Statement HOTEL").snippet("5 star hotel of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.statementes)));

    InfoWindowData stateinfo = new InfoWindowData();
    stateinfo.setImage(("allstates"));
    stateinfo.setRatings("quite nice");

    CustomInfoWindowGoogleMap stateInfoWindow = new CustomInfoWindowGoogleMap(this);
    mMap.setInfoWindowAdapter(stateInfoWindow);

    StateMark.setTag(stateinfo);

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {

    Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();


    }
    });

    mMap.setMyLocationEnabled(true);
    mMap.animateCamera(CameraUpdateFactory.zoomTo(4.0f));
    //mMap.animateCamera(CameraUpdateFactory.zoomIn());
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.setMinZoomPreference(4.0f);
    mMap.setMaxZoomPreference(17.0f);
    //mMap.resetMinMaxZoomPreference();

    } else {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    requestPermissions(new String{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
    }
    }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case MY_PERMISSION_FINE_LOCATION:
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ //&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

    mMap.setMyLocationEnabled(true);
    //mMap.animateCamera(CameraUpdateFactory.zoomTo(13.0f));
    mMap.moveCamera(CameraUpdateFactory.zoomTo(14.0f));
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.setMinZoomPreference(8.0f);
    mMap.setMaxZoomPreference(17.0f);
    }

    } else {
    Toast.makeText(getApplicationContext(), "This service requires location permissions to be granted", Toast.LENGTH_LONG).show();

    }
    break;
    }
    }

    }









    share|improve this question

























      0












      0








      0







      the code runs good without errors however the click event for the custom infowindow returns the same value (toast message) for both marker,i need the custom Infowindows to return the specific toast message within when clicked.



      code:



      public class HotelActivity extends FragmentActivity implements OnMapReadyCallback {



      private GoogleMap mMap;
      private final static int MY_PERMISSION_FINE_LOCATION = 101;

      public static final String Hotdetails = "com.myaddress.Hotdetails";

      @Override
      public Resources getResources(){
      return super.getResources();
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_hotel);

      // Obtain the SupportMapFragment and get notified when the map is ready to be used.
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
      .findFragmentById(R.id.map);
      mapFragment.getMapAsync(this);
      }

      @Override
      public void onMapReady(GoogleMap googleMap) {
      mMap = googleMap;

      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){// ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

      LatLng location1 = new LatLng(9.0454, 7.4797);
      LatLng location2 = new LatLng(9.036190, 7.480130);

      //for location1

      Marker ClassMark = mMap.addMarker(new MarkerOptions().position(eclass).title("E-Class Resorts").snippet("3 star resort of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.eclasses)));

      InfoWindowData Classinfo = new InfoWindowData();
      Classinfo.setImage(("eclass"));
      Classinfo.setRatings("the very best");

      CustomInfoWindowGoogleMap ClassInfoWindow = new CustomInfoWindowGoogleMap(this);
      mMap.setInfoWindowAdapter(ClassInfoWindow);
      ClassMark.setTag(Classinfo);

      mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
      @Override
      public void onInfoWindowClick(Marker marker) {

      Toast.makeText(getApplicationContext(), "This is E-class", Toast.LENGTH_LONG).show();
      }
      });

      //for Location2

      Marker StateMark = mMap.addMarker(new MarkerOptions().position(Statement).title("Statement HOTEL").snippet("5 star hotel of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.statementes)));

      InfoWindowData stateinfo = new InfoWindowData();
      stateinfo.setImage(("allstates"));
      stateinfo.setRatings("quite nice");

      CustomInfoWindowGoogleMap stateInfoWindow = new CustomInfoWindowGoogleMap(this);
      mMap.setInfoWindowAdapter(stateInfoWindow);

      StateMark.setTag(stateinfo);

      mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
      @Override
      public void onInfoWindowClick(Marker marker) {

      Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();


      }
      });

      mMap.setMyLocationEnabled(true);
      mMap.animateCamera(CameraUpdateFactory.zoomTo(4.0f));
      //mMap.animateCamera(CameraUpdateFactory.zoomIn());
      mMap.getUiSettings().setZoomControlsEnabled(true);
      mMap.setMinZoomPreference(4.0f);
      mMap.setMaxZoomPreference(17.0f);
      //mMap.resetMinMaxZoomPreference();

      } else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      requestPermissions(new String{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
      }
      }
      }

      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      switch (requestCode) {
      case MY_PERMISSION_FINE_LOCATION:
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ //&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

      mMap.setMyLocationEnabled(true);
      //mMap.animateCamera(CameraUpdateFactory.zoomTo(13.0f));
      mMap.moveCamera(CameraUpdateFactory.zoomTo(14.0f));
      mMap.getUiSettings().setZoomControlsEnabled(true);
      mMap.setMinZoomPreference(8.0f);
      mMap.setMaxZoomPreference(17.0f);
      }

      } else {
      Toast.makeText(getApplicationContext(), "This service requires location permissions to be granted", Toast.LENGTH_LONG).show();

      }
      break;
      }
      }

      }









      share|improve this question













      the code runs good without errors however the click event for the custom infowindow returns the same value (toast message) for both marker,i need the custom Infowindows to return the specific toast message within when clicked.



      code:



      public class HotelActivity extends FragmentActivity implements OnMapReadyCallback {



      private GoogleMap mMap;
      private final static int MY_PERMISSION_FINE_LOCATION = 101;

      public static final String Hotdetails = "com.myaddress.Hotdetails";

      @Override
      public Resources getResources(){
      return super.getResources();
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_hotel);

      // Obtain the SupportMapFragment and get notified when the map is ready to be used.
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
      .findFragmentById(R.id.map);
      mapFragment.getMapAsync(this);
      }

      @Override
      public void onMapReady(GoogleMap googleMap) {
      mMap = googleMap;

      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){// ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

      LatLng location1 = new LatLng(9.0454, 7.4797);
      LatLng location2 = new LatLng(9.036190, 7.480130);

      //for location1

      Marker ClassMark = mMap.addMarker(new MarkerOptions().position(eclass).title("E-Class Resorts").snippet("3 star resort of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.eclasses)));

      InfoWindowData Classinfo = new InfoWindowData();
      Classinfo.setImage(("eclass"));
      Classinfo.setRatings("the very best");

      CustomInfoWindowGoogleMap ClassInfoWindow = new CustomInfoWindowGoogleMap(this);
      mMap.setInfoWindowAdapter(ClassInfoWindow);
      ClassMark.setTag(Classinfo);

      mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
      @Override
      public void onInfoWindowClick(Marker marker) {

      Toast.makeText(getApplicationContext(), "This is E-class", Toast.LENGTH_LONG).show();
      }
      });

      //for Location2

      Marker StateMark = mMap.addMarker(new MarkerOptions().position(Statement).title("Statement HOTEL").snippet("5 star hotel of excellence").icon(BitmapDescriptorFactory.fromResource(R.drawable.statementes)));

      InfoWindowData stateinfo = new InfoWindowData();
      stateinfo.setImage(("allstates"));
      stateinfo.setRatings("quite nice");

      CustomInfoWindowGoogleMap stateInfoWindow = new CustomInfoWindowGoogleMap(this);
      mMap.setInfoWindowAdapter(stateInfoWindow);

      StateMark.setTag(stateinfo);

      mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
      @Override
      public void onInfoWindowClick(Marker marker) {

      Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();


      }
      });

      mMap.setMyLocationEnabled(true);
      mMap.animateCamera(CameraUpdateFactory.zoomTo(4.0f));
      //mMap.animateCamera(CameraUpdateFactory.zoomIn());
      mMap.getUiSettings().setZoomControlsEnabled(true);
      mMap.setMinZoomPreference(4.0f);
      mMap.setMaxZoomPreference(17.0f);
      //mMap.resetMinMaxZoomPreference();

      } else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      requestPermissions(new String{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
      }
      }
      }

      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      switch (requestCode) {
      case MY_PERMISSION_FINE_LOCATION:
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ //&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){

      mMap.setMyLocationEnabled(true);
      //mMap.animateCamera(CameraUpdateFactory.zoomTo(13.0f));
      mMap.moveCamera(CameraUpdateFactory.zoomTo(14.0f));
      mMap.getUiSettings().setZoomControlsEnabled(true);
      mMap.setMinZoomPreference(8.0f);
      mMap.setMaxZoomPreference(17.0f);
      }

      } else {
      Toast.makeText(getApplicationContext(), "This service requires location permissions to be granted", Toast.LENGTH_LONG).show();

      }
      break;
      }
      }

      }






      android






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 19:33









      Coder

      11




      11
























          1 Answer
          1






          active

          oldest

          votes


















          0














          When you set the second setOnInfoWindowClickListener you're erasing the previous one, because the GoogleMap object can only have one.



          Instead of this, set the listener only once and, in this one, find which marker the user clicked with the Marker param passed in the onInfoWindowClick(Marker marker)method.



          Try something like this:



          mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
          @Override
          public void onInfoWindowClick(Marker marker) {
          if (marker.equals(StateMark)) {
          Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();
          } else if (marker.equals(ClassMark)) {
          Toast.makeText(getApplicationContext(), "This is E-Class", Toast.LENGTH_LONG).show();
          }

          }
          });





          share|improve this answer





















          • worked for me, thanks a lot for the fast response too.
            – Coder
            Nov 23 at 8:09











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437140%2fclicklistener-event-for-custom-infowindow-returns-the-same-value-for-all-markers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When you set the second setOnInfoWindowClickListener you're erasing the previous one, because the GoogleMap object can only have one.



          Instead of this, set the listener only once and, in this one, find which marker the user clicked with the Marker param passed in the onInfoWindowClick(Marker marker)method.



          Try something like this:



          mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
          @Override
          public void onInfoWindowClick(Marker marker) {
          if (marker.equals(StateMark)) {
          Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();
          } else if (marker.equals(ClassMark)) {
          Toast.makeText(getApplicationContext(), "This is E-Class", Toast.LENGTH_LONG).show();
          }

          }
          });





          share|improve this answer





















          • worked for me, thanks a lot for the fast response too.
            – Coder
            Nov 23 at 8:09
















          0














          When you set the second setOnInfoWindowClickListener you're erasing the previous one, because the GoogleMap object can only have one.



          Instead of this, set the listener only once and, in this one, find which marker the user clicked with the Marker param passed in the onInfoWindowClick(Marker marker)method.



          Try something like this:



          mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
          @Override
          public void onInfoWindowClick(Marker marker) {
          if (marker.equals(StateMark)) {
          Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();
          } else if (marker.equals(ClassMark)) {
          Toast.makeText(getApplicationContext(), "This is E-Class", Toast.LENGTH_LONG).show();
          }

          }
          });





          share|improve this answer





















          • worked for me, thanks a lot for the fast response too.
            – Coder
            Nov 23 at 8:09














          0












          0








          0






          When you set the second setOnInfoWindowClickListener you're erasing the previous one, because the GoogleMap object can only have one.



          Instead of this, set the listener only once and, in this one, find which marker the user clicked with the Marker param passed in the onInfoWindowClick(Marker marker)method.



          Try something like this:



          mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
          @Override
          public void onInfoWindowClick(Marker marker) {
          if (marker.equals(StateMark)) {
          Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();
          } else if (marker.equals(ClassMark)) {
          Toast.makeText(getApplicationContext(), "This is E-Class", Toast.LENGTH_LONG).show();
          }

          }
          });





          share|improve this answer












          When you set the second setOnInfoWindowClickListener you're erasing the previous one, because the GoogleMap object can only have one.



          Instead of this, set the listener only once and, in this one, find which marker the user clicked with the Marker param passed in the onInfoWindowClick(Marker marker)method.



          Try something like this:



          mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
          @Override
          public void onInfoWindowClick(Marker marker) {
          if (marker.equals(StateMark)) {
          Toast.makeText(getApplicationContext(), "This is Statement", Toast.LENGTH_LONG).show();
          } else if (marker.equals(ClassMark)) {
          Toast.makeText(getApplicationContext(), "This is E-Class", Toast.LENGTH_LONG).show();
          }

          }
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 21:46









          Albert

          964




          964












          • worked for me, thanks a lot for the fast response too.
            – Coder
            Nov 23 at 8:09


















          • worked for me, thanks a lot for the fast response too.
            – Coder
            Nov 23 at 8:09
















          worked for me, thanks a lot for the fast response too.
          – Coder
          Nov 23 at 8:09




          worked for me, thanks a lot for the fast response too.
          – Coder
          Nov 23 at 8:09


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437140%2fclicklistener-event-for-custom-infowindow-returns-the-same-value-for-all-markers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo