title: restart fragment class when back button press
body: <p>I have a fragment that is part of tab view. I want to restart this fragment when I press back button. but i don't know how to refresh it.
  i tried some codes like this:
  <a href="https://stackoverflow.com/questions/13989300/restart-fragment-inside-activity">Restart fragment inside activity</a> but it didn't work.</p>
  
  <p>here is a code for detecting back button:</p>
  
  <pre><code>    @Override
  public void onResume() {
  
      super.onResume();
  
      getView().setFocusableInTouchMode(true);
      getView().requestFocus();
      getView().setOnKeyListener(new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
  
              if (event.getAction() == KeyEvent.ACTION_UP &amp;&amp; keyCode == KeyEvent.KEYCODE_BACK){
  
                  // handle back button
  
  
  
  
                  return true;
  
              }
  
              return false;
          }
      });
  }
  </code></pre>
  
  <p>here is a fragment class button:</p>
  
  <pre><code>public class MoviesFragment extends Fragment {
  
    static ListView list;
  
  
  static String[] numbers_text = new String[] { "one", "two", "three", "four",
          "five", "six", "seven", "eight", "nine", "ten", "eleven",
          "twelve", "thirteen", "fourteen", "fifteen" };
  String[] songs = new String[] { "1", "2", "3", "4", "5", "6", "7",
          "8", "9", "10", "11", "12", "13", "14", "15" };
  
  
  
  MainCustomList adapter;
  
  
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  
  
  
      View view = inflater.inflate(R.layout.fragment_movies, container, false);
  
      adapter = new MainCustomList(this.getActivity(), numbers_text);
           list=(ListView) view.findViewById(R.id.list);
           list.setAdapter(adapter);
  
  
           return view;
  }
  </code></pre>
  
  <p>main: </p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements
      ActionBar.TabListener {
  
  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  // Tab titles
  private String[] tabs = { "Top Rated", "Games", "Movies" };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // Initilization
      viewPager = (ViewPager) findViewById(R.id.pager);
      actionBar = getActionBar();
      mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
  
      viewPager.setAdapter(mAdapter);
      actionBar.setHomeButtonEnabled(false);
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
  
      // Adding Tabs
      for (String tab_name : tabs) {
          actionBar.addTab(actionBar.newTab().setText(tab_name)
                  .setTabListener(this));
      }
  
      /**
       * on swiping the viewpager make respective tab selected
       * */
      viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
          @Override
          public void onPageSelected(int position) {
              // on changing the page
              // make respected tab selected
              actionBar.setSelectedNavigationItem(position);
          }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) {
          }
      });
  }
  
  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
  }
  
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
      // on tab selected
      // show respected fragment view
      viewPager.setCurrentItem(tab.getPosition());
  }
  
  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  }
  
   }
  </code></pre>