Call Another Fragment Page When Clicking Google Map Infowindow
I am using retrofit to fetch data online.However I cannot find any solution to my problem. I want to call another fragment and display more of the details about the marker I clicke
Solution 1:
You need to use this:
@OverridepublicbooleanonMarkerClick(Marker marker) {
// call fragment and pass data.returnfalse;
}
If you return false the click is not consumed. If you need help implementing this let me know, it's fairly simple.
Here is a quick sample, please change the names to match your own code:
publicclassMapActivityimplementsOnMapReadyCallback, GoogleMap.OnMarkerClickListener {
privateGoogleMap mGoogleMap;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
initMap();
}
publicvoidinitMap() {
MapFragment map = (MapFragment) getFragmentManager().findFragmentById(R.id.mapFragment);
map.getMapAsync(this);
}
@OverridepublicvoidonMapReady(GoogleMap googleMap) {
try {
if (googleMap != null) {
mGoogleMap = googleMap;
mGoogleMap.setOnMarkerClickListener(this);
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Now make your retrofit call
}
} catch (Exception e) {
e.printStackTrace();
Log.e("ERROR", "GOOGLE MAPS NOT LOADED");
}
}
@OverridepublicbooleanonMarkerClick(Marker marker) {
Bundle bundle = newBundle();
bundle.putString("myString", "value");
// set Fragment class ArgumentsMyFragment myFragment= newMyFragment();
myFragment.setArguments(bundle);
// launch fragmentreturnfalse;
}
}
Solution 2:
better to use interface in fragment and implement that interface in (activity where RestAdapter used)
Post a Comment for "Call Another Fragment Page When Clicking Google Map Infowindow"