How to handle click event component of custom marker in android
Asked Answered
T

1

1

I have used xml layout to make marker .In that layout there is five buttons 'A','B','C','D','E'. I follow this link.I want to show different toast message click on different button like if user click on button 'A' then message will be 'you have clicked on button A'. .marker in imageHow to do that? Please help. Thanks in advance.

Twotone answered 7/10, 2017 at 16:16 Comment(0)
S
0
Marker a,b;
GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
a= mMap.addMarker(new MarkerOptions()
    .position(sc)
    .title("A")
    .snippet("A")
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.a)));
b= mMap.addMarker(new MarkerOptions()
    .position(lng)
    .title("B")
    .snippet("B")
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.b)));
mMap.setOnMarkerClickListener(new OnMarkerClickListener()
{
    @Override
    public boolean onMarkerClick(Marker arg0) {
        // if marker source is clicked
        if(arg0.getTitle().equals("A")){
            // display toast
            Toast.makeText(MainActivity.this, arg0.getTitle(), Toast.LENGTH_SHORT).show();
        }
        // if marker source is clicked
        else if(arg0.getTitle().equals("B")){
            Toast.makeText(MainActivity.this, arg0.getTitle(), Toast.LENGTH_SHORT).show();
        }
        return true;
    }
});
Sigismundo answered 7/10, 2017 at 16:29 Comment(1)
hello Shubham a and b not different marker , A,B,C,D, E are component of markerTwotone

© 2022 - 2024 — McMap. All rights reserved.