Android Map (V2) Marker InfoWIndowClickListener fr

2019-07-24 16:16发布

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.

标签: android maps
1条回答
该账号已被封号
2楼-- · 2019-07-24 16:55

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);
                }
            });
        }
查看更多
登录 后发表回答