1

I'm using a FragmentActivity with a FragmentTabHost created dinamically. I want to refresh the fragment hosted in the current tab by clicking an item in the action bar.

This is the code in the FragmentActivity that creats the Tabs and the Fragments:

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

        [...]

        while (iteratorHalls.hasNext()) {

           hallFragment = new HallFragment();
           bundle = new Bundle();
           bundle.putString("Code", hallTmp.getCode());


           TabSpec tabspec=mTabHost.newTabSpec("hall_" + i);
           tabspec.setIndicator(hallTmp.getDescription());
           mTabHost.addTab(tabspec, hallFragment.getClass(), bundle);


           hallFragment.setArguments(bundle);
           i++;

        }
        [...]
    }



    @Override
  public boolean onOptionsItemSelected(MenuItem item) {

       switch (item.getItemId()) {
       case R.id.menu_refresh:

        // HERE I WANT TO REFRESH MY CURRENT FRAGMENT
        return true;

       default:
       return super.onOptionsItemSelected(item);

    }
lory105
  • 6,112
  • 4
  • 31
  • 40
  • try refer below urls : http://stackoverflow.com/questions/13626956/how-to-refresh-fragment-tab-content-on-button-click-android-eclipse http://stackoverflow.com/questions/11578000/android-how-to-restart-refresh-a-fragment-from-fragmentactivty http://stackoverflow.com/questions/12606831/refresh-fragment-view-when-button-is-clicked – KOTIOS Jun 19 '13 at 10:55

1 Answers1

0

you may try in your fragment class:

@Override  
public void setUserVisibleHint(boolean isVisibleToUser) { 
super.setUserVisibleHint(isVisibleToUser);  
    if (isVisibleToUser) {
      //do something
    }
}

Refresh and Worked for me. :)

Amit Kumar Khare
  • 565
  • 6
  • 17