title: Recyclerview not refreshing data in a fragment with viewpager
body: <p>I'm using recyclerview to display local images and videos from sd card when I delete any video or image from my fragment it is deleted but it stays there. I have to go back to show the change in data. My recycler view doesn't refresh automatically doesn't refresh automatically. Can anyone tell me how to fix it
  Here is my code.</p>
  
  <p><strong>RecyleAdapter.java</strong></p>
  
  <pre><code>    public class SavedRecycleAdapter extends RecyclerView.Adapter&lt;SavedRecycleAdapter.MyViewHolder&gt; {
      private static String DIRECTORY_SAVE_MEDIA = "/storage/emulated/0/Folder/";
  
      private ArrayList &lt;File&gt; filesList;
      private Activity activity;
      Context context;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
          ImageView videosThumbnail, picturesThumbnail;
          ImageButton imageDelete, imageShare, videoShare, videoDelete;
          CardView videoCardView, imageCardView;
  
  
          public MyViewHolder(View itemView) {
              super(itemView);
              picturesThumbnail = itemView.findViewById(R.id.imagesThumbnailSaved);
              videosThumbnail = itemView.findViewById(R.id.videosThumbnailSaved);
              imageDelete = itemView.findViewById(R.id.imageDeleteSaved);
              imageShare = itemView.findViewById(R.id.imageShareSaved);
              videoDelete = itemView.findViewById(R.id.videoDeleteSaved);
              videoShare = itemView.findViewById(R.id.videoShareSaved);
              videoCardView = itemView.findViewById(R.id.videoCardViewSaved);
              imageCardView = itemView.findViewById(R.id.imageCardViewSaved);
          }
      }
  
      public SavedRecycleAdapter(ArrayList &lt;File&gt; filesList, Activity activity) {
          this.filesList = filesList;
          this.activity = activity;
      }
  
  
   @Override
      public SavedRecycleAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View inflatedView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.saved_item_view, parent, false);
          return new SavedRecycleAdapter.MyViewHolder(inflatedView);
  
      }
  
      @Override
      public void onBindViewHolder(final SavedRecycleAdapter.MyViewHolder holder, int position) {
          final File currentFile = filesList.get(position);
  
          if (currentFile.toString().endsWith(".mp4")) {
              holder.videoCardView.setVisibility(View.VISIBLE);
              holder.imageCardView.setVisibility(View.GONE);
  
              Glide.with(activity)
                      .load(Uri.fromFile(new File(currentFile.getAbsolutePath())))
                      .into(holder.videosThumbnail);
              holder.videoDelete.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      File file = new File(currentFile.getAbsolutePath());
                      boolean deleted = file.delete();
  
                      //
                  }
              });
              holder.videosThumbnail.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      Intent intent = new Intent(activity, VideoViewerActivity.class);
                      intent.putExtra("video", currentFile.getAbsolutePath());
                      activity.startActivity(intent);
  
                  }
              });
  
              holder.videoShare.setOnClickListener(new View.OnClickListener() {
                 //Do stuff
  
  
          } else {
              holder.videoCardView.setVisibility(View.GONE);
              holder.imageCardView.setVisibility(View.VISIBLE);
  
  
              Glide.with(activity).load(currentFile.getAbsolutePath())
                      .skipMemoryCache(false)
                      .crossFade().into(holder.picturesThumbnail);
              holder.imageDelete.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      File file = new File(currentFile.getAbsolutePath());
                      boolean deleted = file.delete();
  
  
              holder.picturesThumbnail.setOnClickListener(new View.OnClickListener() {
                  // Do stuff
  
              holder.imageShare.setOnClickListener(new View.OnClickListener() {
  
          }
  
      }
  
      @Override
      public int getItemCount() {
          return filesList.size();
      }
  
  }
  </code></pre>
  
  <p><strong>And here is my code for fragment</strong></p>
  
  <pre><code>public class SavedStoriesFragment extends Fragment {
  RecyclerView recyclerView;
  RecyclerView.LayoutManager layoutManager;
  private static final String FILE_PATH = "/storage/emulated/0/Folder/";
  
  public SavedStoriesFragment() {
      // Required empty public constructor
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.fragment_saved_stories, container, false);
  
      recyclerView=(RecyclerView)v.findViewById(R.id.savedRecyclerView);
      layoutManager = new GridLayoutManager(getContext(),2);
      recyclerView.setLayoutManager(layoutManager);
      recyclerView.addItemDecoration(new ItemDecorationAlbumColumns(
              getResources().getDimensionPixelSize(R.dimen.image_list_space),2));
      getListFiles(new File(FILE_PATH));
      SavedRecycleAdapter ra = new SavedRecycleAdapter(this.getListFiles(new File(FILE_PATH)), getActivity());
      recyclerView.setAdapter(ra);
  
      return v;
  }
  
  private ArrayList&lt;File&gt; getListFiles(File parentDir) {
      ArrayList&lt;File&gt; inFiles = new ArrayList&lt;File&gt;();
      File[] files;
      files = parentDir.listFiles();
      if (files != null) {
          for (File file : files) {
              if (file.getName().endsWith(".jpg") ||
                      file.getName().endsWith(".png") ||
                      file.getName().endsWith(".jpeg")||
                      (file.getName().endsWith(".mp4") ||
                              file.getName().endsWith(".gif"))) {
                  if (!inFiles.contains(file))
                      inFiles.add(file);
              }
          }
      }
      return inFiles;
  }
  
  
  
  }
  </code></pre>
  
  <p><strong>ViewPagerAdapter.java</strong></p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {
  
  
  ArrayList&lt;Fragment&gt; mFragment = new ArrayList&lt;&gt;();
  ArrayList&lt;String&gt; mTitles = new ArrayList&lt;&gt;();
  
  public void addFragments (Fragment fragment,String tabTitles)
  {
      this.mFragment.add(fragment);
      this.mTitles.add(tabTitles);
  }
  public  ViewPagerAdapter(FragmentManager fm)
  {
      super(fm);
  }
  @Override
  public Fragment getItem(int position) {
      return mFragment.get(position);
  }
  
  @Override
  public int getCount() {
      return mFragment.size();
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      return mTitles.get(position);
  }
  </code></pre>
  
  <p>}</p>