문제

I am trying to add some image button in my marker info. Though the buttons are added in the view but i cat not click on them. When I try to click it clicks on the whole view. My code us given below.

MainActivity.java

private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RelativeLayout base;
    base = (RelativeLayout) findViewById(R.id.base);
    googleMap = ((MapFragment) getFragmentManager().findFragmentById(
            R.id.map)).getMap();
    try {           
        initilizeMap();   // Loading map
    } catch (Exception e) {
        Log.d("asdfadfadf", "asdfasdf");
    }       
    googleMap.setMyLocationEnabled(true);
    //googleMap.clear();
    IconGenerator i = new IconGenerator(getBaseContext());
    i.setStyle(IconGenerator.STYLE_BLUE);
    Bitmap tt = i.makeIcon("asdf");
    LatLng myLocation = new LatLng(22.899171, 89.500186);
    Marker myLocMarker = googleMap.addMarker(new MarkerOptions()
    .position(myLocation)
    .icon(BitmapDescriptorFactory.fromBitmap(tt))
    .title("sssss"));
    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker mk) {
            // TODO Auto-generated method stub

            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {
            // TODO Auto-generated method stub
            ImageButton set,from,favor;
            View view = getLayoutInflater().inflate(R.layout.marker_info,null);
            set = (ImageButton) view.findViewById(R.id.imageButtonDestination);
            from = (ImageButton) view.findViewById(R.id.imageButtonFrom);
            favor = (ImageButton) view.findViewById(R.id.imageButtonFavourite);
            set.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Log.d("sssssssssssssssss", "sssssssssssssssss");
                }
            });
            return view;
        }
    });
}

/**
 * function to load map. If map is not created it will create it for you
 * */
private void initilizeMap() {
    if (googleMap == null) {
        Toast.makeText(getApplicationContext(),
                "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                .show();
    }
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();  // check if map is created successfully or not
    }
}

@Override
protected void onResume() {
    super.onResume();
    initilizeMap();
}

}

don't know what to do. Thanks in advance.

도움이 되었습니까?

해결책

You can't add click listeners to the Marker's InfoWindow as it's not a real view. But a Bitmap that gets rendered from you layout.

From Google Docs: https://developers.google.com/maps/documentation/android/marker#info_windows

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

다른 팁

Set GoogleMap.OnInfoWindowClickListener() to your map, implement the interface. You get the marker passed to you, call you action form there:

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override public void onInfoWindowClick(Marker marker) {
        //do your thing here
        }
});

I don't understand very well what you require, but according understanding is something of a click on an image to add to the map (a marker). if so may try this:

googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker arg0) {
            //Your code when you do click

            return false;
        }
    });

I hope help you, and Sorry for my english :(

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top