i'm working on android project, i want to send an arraylist of object that contain latitude and longitude from a fragment to another fragment to show multiple marker on the map but i get an empty argument.
First Fragment
private ArrayList<locationList> beirutList = new ArrayList<locationList>();
beirutList.add(new locationList(34.077867,33.76087));
Fragment mapapp = new MapApp();
FragmentManager fragmentManager = getFragmentManager();
Bundle data = new Bundle();
data.putParcelableArrayList("list", beirutList);
mapapp.setArguments(data);
fragmentManager.beginTransaction().replace(R.id.content_frame, mapapp, "MappFrag").addToBackStack(null).commit();
Second Fragment
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.map_app, container,
false);
data = null;
if (getArguments() != null) {
data = getArguments();
Log.e("MapApp", "data is " + data.toString());
if (data.getParcelableArrayList("list") != null) {
beirutList = data.getParcelableArrayList("list");
} else
Toast.makeText(rootview.getContext(), "location is empty ", Toast.LENGTH_LONG).show();
}
try {
MapsInitializer.initialize(rootview.getContext());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
mLocationClient = new LocationClient(rootview.getContext(), this, this);
mLocationClient.registerConnectionCallbacks(this);
mLocationClient.connect();
return rootview;
}
when i debug it the list in the Bundle (data variable) has the size 0
locationList class
public class locationList implements Parcelable {
private double latitude;
private double longitude;
public static final Parcelable.Creator<locationList> CREATOR = new Parcelable.Creator<locationList>() {
@Override
public locationList createFromParcel(Parcel source) {
return new locationList(source);
}
@Override
public locationList[] newArray(int size) {
return new locationList[size];
}
};
@Override
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeDouble(latitude);
dest.writeDouble(longitude);
}
private locationList (Parcel bei){
this.latitude = bei.readDouble();
this.longitude = bei.readDouble();
}
public locationList(){
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public locationList(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
}