【问题标题】:android GoogleMap setOnInfoWindowClickListener - abstract methodandroid GoogleMap setOnInfoWindowClickListener - 抽象方法
【发布时间】:2017-08-24 08:35:59
【问题描述】:

欢迎,我对 GooleMap onInfoWindowClick 有疑问。 安卓显示错误: "com.example.ann.myapp$1 不是抽象的,并且不会覆盖 OnInfoWindowClickListener 中的抽象方法 onInfoWindowClick(Marker)"

我不明白,因为注释的方法 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;
//            }
//        });



    }

}

【问题讨论】:

    标签: android abstract


    【解决方案1】:

    void 而不是布尔值!!!!

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

    【讨论】:

      猜你喜欢
      • 2021-10-13
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多