you can parse like this:
List<RidesData> ridesDatas; /* this is should be parcelable */
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(FragmentAbout.newInstance(ridesDatas), "ABOUT");
adapter.addFragment(FragmentPointOfInterest.newInstance(ridesDatas),"POI");
viewPager.setAdapter(adapter);
}
and set constructure to each fragment like this:
FragmentAbout.class
public static FragmentAbout newInstance(List<RidesData> ridesDatas) {
FragmentAbout fragmentAbout = new FragmentAbout();
Bundle arg = new Bundle();
arg.putParcelableArrayList("data", (ArrayList<? extends Parcelable>) ridesDatas);
fragmentAbout.setArguments(arg);
return fragmentAbout;
}
FragmentPointOfInterest.class
public static FragmentPointOfInterest newInstance(List<RidesData> ridesDatas) {
FragmentPointOfInterest fragmentPointOfInterest = new FragmentPointOfInterest();
Bundle arg = new Bundle();
arg.putParcelableArrayList("data", (ArrayList<? extends Parcelable>) ridesDatas);
fragmentPointOfInterest.setArguments(arg);
return fragmentPointOfInterest;
}
and get each data of json in onViewCreated()
method of fragment like this:
you have 2 position of data in json.
[0] = c_id=13
[1] = c_id=14
so in first fragment set 0 position:
RidesData data = ridesData.get(0);
and in second Fragment set 1 postion:
RidesData data = ridesData.get(1);
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ridesData = new ArrayList<>();
ridesData = getArguments().getParcelableArrayList("data");
RidesData data = ridesData.get(1);
}
7
solved How to parse JSON data into fragments?