2017-08-24 68 views
0

歡迎,我有問題與GooleMap onInfoWindowClick。 安卓顯示錯誤: 「com.example.ann.myapp $ 1不是抽象的,沒有犯規重寫抽象方法onInfoWindowClick(標記)在OnInfoWindowClickListener」android GoogleMap setOnInfoWindowClickListener - 抽象方法

我不明白它,因爲評價方法 setOnMarkerClickListener 工作正常。我只是改變setOnMarkerClickListener到 setOnWindowClickListener

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 
    private ArrayList<LatLng> latlngs = new ArrayList<>(); 
    ArrayList<ImageItem> allItems = new ArrayList<>(); 

    private MarkerOptions options = new MarkerOptions(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map); 
     mapFragment.getMapAsync(this); 

     latlngs.add(new LatLng(54.353728,18.65954)); 
     latlngs.add(new LatLng(54.353001,18.657567)); 
     latlngs.add(new LatLng(54.353747,18.65938)); 

    } 





    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 


     LatLng sydney = new LatLng(54.353001, 18.657567); 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 


// ************* here is the problem **************** 
     mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() 
     { 

      @Override 
      public boolean onInfoWindowClick(Marker arg0) { 
       // if(arg0.getTitle().equals("MyHome")) // if marker source is clicked 
       Toast.makeText(getApplicationContext(), arg0.getTitle(), Toast.LENGTH_SHORT).show();// display toast 
       return true; 
      } 

     }); 

// ************* end of the problem **************** 


//  mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { 
//   @Override 
//   public boolean onMarkerClick(Marker marker) { 
//    marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.logo)); 
//    return false; 
//   } 
//  }); 



    } 

} 

回答

0

無效,而不是布爾!!!!

mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() 
{ 

    @Override 
    public void onInfoWindowClick(Marker arg0) { 
     // if(arg0.getTitle().equals("MyHome")) // if marker source is clicked 
     Toast.makeText(getApplicationContext(), arg0.getTitle(), Toast.LENGTH_SHORT).show();// display toast 

    } 

});