Passing custom List of data using Bundle

xenuit picture xenuit · May 3, 2014 · Viewed 25.2k times · Source

I'm developing a simple app, that contains tabview with fragment. I am stuck at the place, where i have to pass data to my newly created fragment on tabselect.

I have a List of lists of my custom class objects:

List<List<NewsObjectClass>> myList;

Here is where I got stuck:

public static class PlaceholderFragment extends ListFragment{

    private static final String ARG_SECTION_NUMBER = "section_number";


    public PlaceholderFragment(){       

    }


    public static PlaceholderFragment newInstance(int sectionNumber, List<List<NewsObjectsClass>> data)  {

        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);

        // Here i want to pass my List<List<NewsObjectClass>> to the bundle

        fragment.setArguments(args);
        return fragment;
    }
...

So specifically i need a way how to pass my list of lsits of myCustomObjects to the fragment, so there I could use it for lsitview adapter.

Any syggestions on how to pass this type of data would be great. Thanks.

Answer

Alireza Sobhani picture Alireza Sobhani · Jan 18, 2016
args.putParcelableArrayList(DATA_KEY, new ArrayList<>(data));