我是android的初学者。我已经实现了Google Map v2,但我想要一个带有三个按钮的自定义信息窗口,我浏览了文档,但默认的信息窗口是单击的,它不能有按钮,任何方式或想法我都可以做到这一点。请帮帮我。
答案 0 :(得分:1)
你想要实现的目标是可能的。
您可以在此答案中看到食谱:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)
上的工作实施此处还有一个小tutorial
答案 1 :(得分:0)
你需要像这样创建一个自定义窗口
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);
}
}
你可以像这样调用这个函数
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()));
这就是你如何调用infowindo map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));