问题
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