2014-02-25 116 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

相關問題