Adding a button to a custom InfoWindowAdapter view that can register clicks

巧了我就是萌 提交于 2019-12-04 08:20:50

问题


I'm adding an InfoWindowAdapter with a custom layout to the Android Google Maps API v2 based map fragment. I've put a button in the view I return from getInfoWindow() and while it shows up perfectly fine, when I click on said button the window itself registers a click (blinking with a yellowish tint as usual) while the button does not.

How can I make a button in the info window "clickable"? And, by extension, any view inside an info window?


回答1:


Instead, listen for marker click events with OnMarkerClickListener and display your own complete view directly. It may be a bit more work to anchor it to the location of the marker, however. Try PopupWindow with showAtLocation(View parent, int gravity, int x, int y)




回答2:


While you can set an info window to be an arbitrary view using GoogleMap.setInfoWindowAdapter(), the info window that is rendered on the map is not a live view. Instead, it is a snapshot of the view at the time the view was returned by the adapter (see here). So, unfortunately it doesn't behave like a standard view once it is placed on the map.




回答3:


Maybe you can set a customize AlartDialog in InfoWindowClickListener to switch something event

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {          
        public void onInfoWindowClick(Marker marker) {
            String[] items={"onefunction","twofunction"};
            AlertDialog.Builder itemDilog = new AlertDialog.Builder(context);
            itemDilog.setTitle("");
            itemDilog.setCancelable(false);
            itemDilog.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    switch(which){
                    case 0:{
                            onefunction();
                            }break;
                    case 1:{
                            twofunction();
                            }break; 
                    }

                }
            });
            itemDilog.show();

        }
    });



回答4:


CustomInfoWindowAdapter set tag:

mWindow.findViewById(R.id.chat).setTag("chatTag"); // button

and:

  @Override
public void onInfoWindowClick(Marker marker) {


   if(customInfoWindowAdapter.getInfoContents(marker).findViewById(R.id.chat).getTag().equals("chatTag")) {
      // any code here
   }
}


来源:https://stackoverflow.com/questions/13706925/adding-a-button-to-a-custom-infowindowadapter-view-that-can-register-clicks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!