2014-02-25 46 views
0

我是Android的初学者。我已经实现了谷歌地图v2,但我想要一个带有三个按钮的自定义信息窗口,我经历了文档,但默认的infowindow是单点击,它不能有按钮,任何方式或想法,我可以做到这一点。请帮助我。Android Google Map V2 InfoWindow

回答

1

你是什么试图实现是可能的。

你可以看到在这个答案配方:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)

而且在Google Play

而且也在这里工作实施小tutorial

+0

非常感谢@M D.我会试试这个。 –

+0

@VishnuPrabhu这是有史以来最好的成就becoz'自定义信息窗口只提供一次点击,但你可以通过使用上述后解决方案实现特定的按钮点击 –

+1

@MD自定义窗口也允许实现特定的按钮点击查看我的回答 – Jagan

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())); 

这为u如何调用infowindo map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));

+0

非常感谢贾根,我会尝试。 –

+0

在上面的代码中,你在哪里设置按钮的点击监听器@Jagan –

+0

@Vishnu Prabhu c我编辑的答案按钮点击 – Jagan