Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The listener solution you found is excellent and actually recommended by Google (<a href="http://developer.android.com/training/basics/fragments/communicating.html" rel="nofollow">http://developer.android.com/training/basics/fragments/communicating.html</a>).</p> <p>As for your remaining problem of passing data to fragments, are you sure you need the entire list passed, and not just an element of the list for each fragment in the ViewPager? If you just need an element, you can do something like this:</p> <pre><code> /* * An adapter for swiping through the fragments we have. */ private class CustomPagerAdapter extends FragmentStatePagerAdapter { List&lt;Thing&gt; things; public CustomPagerAdapter(FragmentManager fragmentManager, List&lt;Thing&gt; things) { super(fragmentManager); this.things = things; } @Override public int getCount() { return things.size(); } @Override public Fragment getItem(int position) { return ThingFragment.newInstance(things.get(position)); } } /* * Loads a view based on the thing. */ private static class ThingFragment extends Fragment { private String name; static ThingFragment newInstance(Thing thing) { ThingFragment f = new ThingFragment(); // add some arguments to our fragment for onCreateView Bundle args = new Bundle(); args.putString("name", thing.getName()); f.setArguments(args); return f; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); name = getArguments().getString("name"); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.thing_fragment_layout, container, false); TextView t = (TextView)v.findViewById(R.id.thingText); t.setText(name); return v; } } </code></pre> <p>And pass your list to the adapter. Of course, this requires that your dynamics be created dynamically, but inflating xml fragments is really easy.</p> <p>If you actually DO need to pass the entire list, yeah, you might have to make the individual complex object Parcelable, and then add it to your Fragment args like with Bundle.putParcelableArray().</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload