问题
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'. .How to do that? Please help. Thanks in advance.
回答1:
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;
}
});
来源:https://stackoverflow.com/questions/46622384/how-to-handle-click-event-component-of-custom-marker-in-android