How to pass an ArrayList from Activity to a Fragment
<p>What I'm trying to do is send an <code>ArrayList&lt;String&gt;</code> from an <strong>Activity</strong> to a <strong>ListFragment</strong>.</p>

<p>So I can use the Fragments in a <code>TableLayout</code>.</p>

<p>It's not necessary to use a <code>ListFragment</code>, I can use any type of <code>Fragment</code>, but I'm trying to get the idea.</p>

<p>Here's my <strong>MainActivity</strong>:</p>

<pre><code>FragmentTransaction fragmentTransaction;

ArrayList&lt;String&gt; namesArray = new ArrayList&lt;&gt;();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    namesArray.add("Android");
    namesArray.add("Iphone");
    namesArray.add("Windows Phone");

    Bundle bundle = new Bundle();
    bundle.putStringArrayList("valuesArray", namesArray);
    namesFragment myFragment = new namesFragment();
    myFragment.setArguments(bundle);

    fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.main_container, new namesFragment());
    fragmentTransaction.commit();

}
</code></pre>

<p>My <strong>ListFragment</strong>:</p>

<pre><code>@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ArrayList&lt;String&gt; values = getArguments().getStringArrayList("valuesArray");

    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;&gt;(getActivity(), android.R.layout.simple_list_item_1, values);

    setListAdapter(adapter);
}
</code></pre>

<p>This code above gives me:</p>

<blockquote>
  <p>Unfortunately app has stopped.</p>
</blockquote>

<p>So how can I achieve something like that?</p>