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

不打扰是莪最后的温柔 提交于 2019-12-02 22:41:40

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)

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.

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

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