Android Map (V2) Marker InfoWIndowClickListener freezes (then crashes) when start child tab activity

空扰寡人 提交于 2019-12-13 15:39:55

问题


googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    public void onInfoWindowClick(Marker marker) {
        Intent rest_list = new Intent(getParent(), RestFullDetail.class);
        TabGroupActivity parentActivity = (TabGroupActivity)getParent();
        parentActivity.startChildActivity("mapRestDetail", rest_list);
    }
});

When i tap on info window, info window freezes and doesn't navigate to another tab child activity. While freezing and crashing its not producing any logcat information.

Got Solution:

I found solution myself. Try async task excute on infowindowclick and put all the code (which was to run under info window click) in postexecute. It works like charm.


回答1:


You need to follow these steps to perform custom info window click :

--> implement "GoogleMap.OnInfoWindowClickListener" and "GoogleMap.InfoWindowAdapter"

--> Inflate custom info window :

@Override
    public View getInfoContents(Marker marker) {
        // Inflate the layouts for the info window, title and snippet.
        View infoWindow = getActivity().getLayoutInflater().inflate(R.layout.custom_info_contents, null);
        TextView txtStoreName = ((TextView) infoWindow.findViewById(R.id.txtStoreName));
        txtStoreName.setText(marker.getTitle());
        TextView txtStoreAddress = ((TextView) infoWindow.findViewById(R.id.txtStoreAddress));
        txtStoreAddress.setText(marker.getSnippet());
        return infoWindow;
    }

--> Set Listener : // InfoWindowClick

mGoogleMap.setOnInfoWindowClickListener(this);
    @Override
        public void onInfoWindowClick(final Marker marker) {
            // TODO Here perform action on balloon view click
            mRecyclerStore.post(new Runnable() {
                @Override
                public void run() {
                    StoreModel model = (StoreModel) marker.getTag();
                    boolean isAddedToBackStack = true;
                    StoreDetailsAndProductListFragment storeDetailsAndProductListFragment = new StoreDetailsAndProductListFragment();
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(ExtrasUtil.STORE, model);
                    storeDetailsAndProductListFragment.setArguments(bundle);
                    showOtherFragment(storeDetailsAndProductListFragment, getActivity().getFragmentManager(), isAddedToBackStack);
                }
            });
        }


来源:https://stackoverflow.com/questions/16168639/android-map-v2-marker-infowindowclicklistener-freezes-then-crashes-when-star

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