I am a beginner in android. I have implemented Google Map v2, but i Want a custom info Window with three button, I went through Documentation, but the default infowindow is single clickable and it cannot have buttons, any way or idea i can do this. Please help me on this.
Asked
Active
Viewed 964 times
2 Answers
1
What you are trying to achieve is possible.
You can see the recipe in this answer:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)
And a working implementation on Google Play
And also here a small tutorial
-
@VishnuPrabhu this is the best achievement ever becoz `Custom Info Window` only provide single click but you can achieve particular button click by using the above post solution – M D Feb 25 '14 at 06:53
-
1@MD the Custom window also allowed to achieve particular button click see my answer – Jagan Feb 25 '14 at 07:02
-
@Jagan you are right but when i click in any button then it's triggered info window click.it's not triggered particular `Button onClick()`. I have tried this so that i told u. – M D Feb 25 '14 at 07:05
-
@MD but we are using LayoutInflater for infowindow that contain button so it triggered both – Jagan Feb 25 '14 at 07:09
0
U need to create a custom window like this
class BalloonAdapter implements InfoWindowAdapter {
LayoutInflater inflater = null;
private Button Button1, Button2, Button3;
public BalloonAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
@Override
public View getInfoWindow(Marker marker) {
User_ID = marker.getTitle();
View v = inflater.inflate(R.layout.map_ballon, null);
if(User_ID.equals("Your location")){
//Toast.makeText(getApplicationContext(), "your location", Toast.LENGTH_LONG).show();
textViewTitle = (TextView) v.findViewById(R.id.balloon_name);
textViewTitle.setText(marker.getTitle());
}else{
if (marker != null) {
image = (ImageView) v.findViewById(R.id.balloon_image);
Button1= (Button) v.findViewById(R.id.balloon_name);
Button2 = (Button ) v.findViewById(R.id.balloon_age);
Button3 = (Button ) v.findViewById(R.id.balloon_id);
Button1.setText(marker.getTitle());
Button2.setText(marker.getSnippet());
Button3.setVisibility(View.GONE);
imageLoader.DisplayImage(ImageLoad, image);
Button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
Button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
Button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
}
}
return v;
}
@Override
public View getInfoContents(Marker marker) {
return (null);
}
}
and You can call the function like this
map.addMarker(new MarkerOptions()
.position(
new LatLng(
Double.parseDouble(Latitude),
Double.parseDouble(Longitude)))
.title(User_ID + "\n" + "Name: " + CustomerName
+ "\n"+"Gender: " + Gender)
.snippet(PhoneNum+"\n"+ImageStatus+"*"+ImageLoad)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.maponinemarker)));
map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));
this is how u call the infowindo map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));

Jagan
- 692
- 1
- 12
- 38
-
In the above code, where have you set the click listeners for the button @Jagan – Vishnu Prabhu Feb 25 '14 at 06:53