title: Fragment listview update from activity
body: <p>I am pretty new to Android (3 days), but I have a pretty good background in PHP (which may be the cause of my confusion in a Java based environment). I started building an Android app using Android Studio (Beta). I created the default Android Studio activity with the Navigation Drawer Activity. I edited the activity fragment part to look like this:</p>
  
  <pre><code>@Override
  public void onNavigationDrawerItemSelected(int position) {
      Bundle bundle = new Bundle();
      bundle.putStringArrayList("contacts", arr);
      bundle.putStringArrayList("messages", messages);
      Fragment fragment = null;
      switch (position) {
          case 0:
              fragment = new FriendsFragment();
              break;
          case 1:
              fragment = new ChatsFragment();
              break;
          case 2:
              fragment = new GroupsFragment();
              break;
          case 3:
              fragment = new LogoutFragment();
              break;
          default:
              break;
      }
  
      if (fragment != null) {
          fragment.setArguments(bundle);
          FragmentManager fragmentManager = getSupportFragmentManager();
          fragmentManager.beginTransaction()
                  .replace(R.id.container, fragment).addToBackStack(null).commit();
      }
  }
  </code></pre>
  
  <p>As you can see I am passing a Bundle to my Fragments called "messages" and "contacts" when an item is selected in the Navigation Drawer. The "messages" bundle are XMPP messages received by the aSmack library from an OpenFire server. <strong>So basically I'm trying to create a XMPP client.</strong> When I run the app I can receive the messages in the "ChatsFragment".</p>
  
  <p><strong>Now my problem:</strong>
  I have to press the "ChatsFragment" item on the drawer to have my messages updated (re-receive the bundle) everytime I feel like there are new messages received from the server. But I want this to be done automatically by the fragment. </p>
  
  <p>First I would like to know if my procedure is correct (Activity listens to server, creates bundle, send bundle to fragment, bundle updates messages on receive**)</p>
  
  <p>** = This part I haven't been able to understand how to implement. </p>
  
  <p>1- If the procedure is correct tell me how I should get the messages to be updated by the fragment through the activity?</p>
  
  <p>2- If this is not the correct way to do things in Android, recommend me a way of doing it.</p>
  
  <p><strong>My code for displaying the messages in fragment:</strong></p>
  
  <pre><code>private void displayListView() {
  
      // Messages array list
      List&lt;String&gt; contacts = getArguments().getStringArrayList("messages");
      //System.out.println("arr: " + contacts);
  
      //create an ArrayAdaptar from the String Array
      ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(getActivity(),
              R.layout.url_list, contacts);
      ListView listView = (ListView) getView().findViewById(R.id.listView);
      // Assign adapter to ListView
      listView.setAdapter(dataAdapter);
  
      //enables filtering for the contents of the given ListView
      listView.setTextFilterEnabled(true);
  
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              // Send the URL to the host activity
              //mListener.onURLSelected(((TextView) view).getText().toString());
  
          }
      });
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>