title: Switch current fragment on item click
body: <p>I am trying to write a file manager for android as an university project. My idea is to use fragments in it to create a tabbed vew for it with a viewpager. Practically, the first view you get when you load the app is a path selection fragment, where you have sdcard, music, etc. That fragment contains a listview of said folders. When I click on an item, i want another fragment to be added to the pager, and that works fine. But I also want the current fragment to be replaced with a grid view of the "clicked" folder. That doesn't work. I use an arraylist of File[] to store files in each folder i selected. I also added methods inside the fragment adapter to add and replace fragments in my fragment arraylist. Tried with transaction and with my list, the list is correctly updated but the view is not. The following code is the method inside my fragment adapter to replace a fragment. It is called inside an onItemclicklistenr set to my listview:</p>
  
  <pre><code>    public void replaceFragment(SherlockFragment newFragment, int pos) {
      SherlockFragment old=fragments.get(pos);
      fragments.set(pos, newFragment);
      notifyDataSetChanged();
  </code></pre>
  
  <p>}</p>
  
  <p>I read several answers about this issue, tried almost everything, nothing seems to work. Any help would be apreciated.</p>