title: Refresh Current Fragment (ListView Data) remaining in the same activity
body: <p>Calling a <code>Fragment</code> from an <code>Activity</code>, I am displaying a <code>ListView</code> with two <code>Buttons</code>. When I click on a <code>menu_item</code> (i.e. Show Online), i am updating the data and so the <code>ListView</code>. Now I need to reflect the updated data. How can i refresh the <code>Fragment</code> after i click Show Online. Till now, I have used the following code: </p>
  
  <pre><code>Intent intent = getIntent();
  Intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
  finish();
  startActivity(intent);
  </code></pre>
  
  <p>But this will restart the whole <code>Activity</code>. I just need to refresh the current <code>Fragment</code>. </p>
  
  <p><img src="https://i.stack.imgur.com/72xW2.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/aaTC3.png" alt="enter image description here"></p>
  
  <p><strong>Edited : Code Added</strong></p>
  
  <p><strong>ACTIVITY CLASS</strong></p>
  
  <pre><code>    public class ContactListActivity extends ActionBarActivity {
  
      ListView listView;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          final ActionBar actionBar = getActionBar();
          MenuButtonUtil.enableMenuButton(this);
  
          FragmentManager fragmentManager = getFragmentManager();
  
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  
          MyContactsFragment contactListFragment = new MyContactsFragment ();
          fragmentTransaction.replace(android.R.id.content, contactListFragment);
          fragmentTransaction.commit();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          if (id == R.id.show_online) {
              ContentValues values = new ContentValues();
              String where = "((" + ContactsContentProvider.PHONE_ID + " NOTNULL) AND ((" +
                         ContactsContentProvider.PHONE_ID+ " = 17486 )OR (" +
                         ContactsContentProvider.PHONE_ID+ " = 17494 )))";
  
              values.put(ContactsContentProvider.STATUS, true);
              this.getContentResolver().update(ContactsContentProvider.CONTENT_URI, values, where, null);
  
              listView = (ListView) this.findViewById(android.R.id.list);
              ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
  
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
  }
  </code></pre>
  
  <p><strong>Fragment</strong></p>
  
  <pre><code>public class MyContactsFragment extends ListFragment{
  
  Button allContactsBtn;
  Button neeoContactsBtn;
  ListView listView;
  CustomAdapterForAllContacts adapterForAllContacts;
  CustomAdapterForNeeoContacts adapterForNeeoContacts;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      final ActionBar actionBar = getActivity().getActionBar();
      MenuButtonUtil.enableMenuButton(getActivity());
      adapterForNeeoContacts = new CustomAdapterForNeeoContacts();
      adapterForAllContacts = new CustomAdapterForAllContacts();
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.contactsfragment, container,false);
  
      allContactsBtn = (Button) view.findViewById(R.id.allContactsButton);
      neeoContactsBtn = (Button) view.findViewById(R.id.neeoContactsButton);
      listView = (ListView) view.findViewById(android.R.id.list);
  
  
      // ==================== Neeo Contacts ============================
      neeoContactsBtn.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              listView.setAdapter(adapterForNeeoContacts);
  
          }
      });
  
      // ====================== All Contacts =============================
  
      allContactsBtn.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              listView.setAdapter(adapterForAllContacts);
          }
      });
  
      return view;
  }
  </code></pre>
  
  <p><strong>Adapter</strong>:</p>
  
  <pre><code>private class CustomAdapterForAllContacts extends BaseAdapter {
  
  public CustomAdapterForAllContacts(){
  
  }
      List&lt;Contact&gt; contactsList = getAllContacts();
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return contactsList.size();
      }
  
      @Override
      public Contact getItem(int arg0) {
          // TODO Auto-generated method stub
          return contactsList.get(arg0);
      }
  
      @Override
      public long getItemId(int arg0) {
          // TODO Auto-generated method stub
          return arg0;
      }
  
      @Override
      public View getView(int position, View view, ViewGroup viewGroup) {
  
          if(view==null)
          {
              LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              view = inflater.inflate(R.layout.list_item, viewGroup,false);
          }
  
          TextView contName = (TextView)view.findViewById(R.id.nameText);
          TextView contNumber = (TextView)view.findViewById(R.id.numberText);
          ImageView image = (ImageView)view.findViewById(R.id.contact_image);
  
          Contact contact = contactsList.get(position);
  
          String status = contact.getStatus();
  
          if(contact.getStatus().equals("1")){
              image.setBackgroundResource(com.example.mycontentprovider.R.drawable.person_empty_online);
          }else{
              image.setBackgroundResource(com.example.mycontentprovider.R.drawable.person_empty_offline);
          }
  
          contName.setText(contact.getName());
          contNumber.setText(contact.getPhoneNumber());
          return view;
      }
  
      public Contact getContactPosition(int position)
      {
          return contactsList.get(position);
      }
      public List&lt;Contact&gt; getAllContacts(){
  
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;(); 
  
          String URL = "content://com.example.provider.Contacts/contacts";
          Uri baseUri1 = Uri.parse(URL);
          String[] select = {ContactsContentProvider.PHONE_ID, ContactsContentProvider.STATUS};
  
          String where = "((" + ContactsContentProvider.NEEO_USER + " NOTNULL) AND (" +
                                                     ContactsContentProvider.NEEO_USER+ " = 1 )AND (" +
                                                     ContactsContentProvider.STATUS+ " = 1 ))";
  
          Cursor cursor =  getActivity().getContentResolver().query(baseUri1, select, where, null, "pid");
  
          for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()) {
              Log.w("Filtered IDS",""+ cursor.getString(cursor.getColumnIndex(ContactsContentProvider.PHONE_ID))+
                      ""+ cursor.getString(cursor.getColumnIndex(ContactsContentProvider.STATUS)));
          }
  
  
          Uri baseUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
  
          String[] projection = new String[] {
                  ContactsContract.CommonDataKinds.Phone._ID,
                  ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                  ContactsContract.CommonDataKinds.Phone.NUMBER};
  
          String selection = "((" + 
                  ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " NOTNULL) AND (" +
                  ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " != ' ' ))";
  
          String[] selectionArgs = null;
          String sortOrder = ContactsContract.CommonDataKinds.Phone._ID + " COLLATE LOCALIZED ASC";
  
          Cursor mCursor= getActivity().getContentResolver().query(baseUri, projection, selection, selectionArgs, sortOrder);
  
          // Joinging Both Cursors
                  CursorJoiner joiner = new CursorJoiner(cursor, new String[] {ContactsContentProvider.PHONE_ID} , mCursor, new String[] {ContactsContract.CommonDataKinds.Phone._ID});
                  for (CursorJoiner.Result joinerResult : joiner) {
                      Contact cont = new Contact();
                      Log.e("Result", joinerResult.toString());
                      switch (joinerResult) {
                      case LEFT:
                          // handle case where a row in cursorA is unique
                          break;
                      case RIGHT:
                          // handle case where a row in cursorB is unique
                          cont.setID(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID)));
                          cont.setName(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
                          cont.setPhoneNumber(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
                          cont.setStatus("0");
                          contactList.add(cont);
                          break;
                      case BOTH:
                          // handle case where a row with the same key is in both cursors
                          cont.setID(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID)));
                          cont.setName(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
                          cont.setPhoneNumber(mCursor.getString(mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
                          cont.setStatus(cursor.getString(cursor.getColumnIndex(ContactsContentProvider.STATUS)));
                          contactList.add(cont);
                          break;
                      }
                  }
                  mCursor.close();
                  cursor.close();
          return contactList;
      }
  }  
  </code></pre>