android GoogleMap setOnInfoWindowClickListener - 抽象方法

时间:2017-08-24 08:35:59

标签: android abstract

欢迎,我对GooleMap onInfoWindowClick有疑问。 Android显示错误: “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;
//            }
//        });



    }

}

1 个答案:

答案 0 :(得分:0)

void而不是boolean !!!!

Sheet2