title: overriding back button in fragment
body: <p>I have an activity with different fragments in the tab selection, I want to override the back button so that it calls a method in the fragment that update the listview to the parent folder list.
  For now I've made this in the main activity:</p>
  
  <pre><code>    @Override
          public void onBackPressed()
          {
              ActionBar actionbar = getActionBar();
              if(actionbar.getSelectedTab().getPosition() == 0)
              {
                  if(!fla.onBackPressed())
                      super.onBackPressed();
              }
          }
  </code></pre>
  
  <p>And this in the fragment:</p>
  
  <pre><code>   public boolean onBackPressed()
      {
          if(back_str.equals(MAIN_POINT)){
              Log.v("A", "BACK FIRST" + back_str);
              return false;
              }
          else
          {
              Log.v("A", "BACK PREMUTO");
              updateListViewFolder(back_str);
              return true;  //torna indietro nella view
          }
      }
  </code></pre>
  
  <p>back_str is a global string in the class referring to the current parent directory in the listview and it's updated every time I open a folder.</p>
  
  <p>Seems that when I press the back button back_str is always = null</p>
  
  <p>can someone help me and tell me a way I can solve this?</p>
  
  <p>EDIT: </p>
  
  <p>I'll try to explain me better, I've a listview inside the fragment that I use to navigate into the folder of the phone, starting from /storage/ when I press a folder it opens updating the listview calling this method:</p>
  
  <pre><code>public void updateListViewFolder(String newPath)
  {
      ArrayList&lt;Song&gt; songsListTMP = new SongManager().getPlayList(newPath); //aggiungo tutte le canzoni
      songsListData.removeAll(songsListData);
  
      //AGGIUNGO LA CARTELLA PRECEDENTE
      File here = new File(newPath);
      back_str = here.getParent();
      Log.v("A", "S:"+back_str);
      Song back = new Song(back_str, true); //Sono directory
      songsListData.add(back);
  
      for(int i = 0; i &lt; songsListTMP.size(); i++)
      {
          Song song = songsListTMP.get(i);
          songsListData.add(song); //tengo un attimo separate
      }
  
          for(File dir : here.listFiles() )
          {
              if(dir.isDirectory() &amp;&amp; dir.canRead()){
                  Song sdir = new Song(dir.getPath(), true); //Sono directory
                  songsListData.add(sdir);
              }
          }
  
      getListView().invalidateViews();
  
      }
  </code></pre>
  
  <p>Now I want to return to the parent folder if the back button is selected, but somehow I get errors when I try to call the method onBackPressed of the fragment from the activity. I'm using a static variable string_str to store inside my fragment the path of the parent folder I want to update the list with, but somehow I can't get the list updated with the same updateListViewFolder method</p>