title: How to Swipe Refreshing Layout In Recyclerview Like (YouTube)
body: <p>How To Refresh <strong>RecyclerView</strong> List Like YouTube By Swiping Refresh layout<p>
  <strong>activity_main.xml:-</strong>
  This Is My Main Activity java</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".ImagesActivity"&gt;
      &lt;ProgressBar
          android:id="@+id/progress_circle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true" /&gt;
  
      &lt;android.support.v4.widget.SwipeRefreshLayout
          android:id="@+id/Swipe_Refresh"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;     
      &lt;/android.support.v4.widget.SwipeRefreshLayout&gt; 
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong> 
  And This Is My MainActivity.Java+
  please tell me the code </p>
  
  <pre><code>   public class ImagesActivity extends AppCompatActivity implements ImageAdapter.OnItemClickListener {
          private RecyclerView mRecyclerView;
          private ImageAdapter mAdapter;
  
          private ProgressBar mProgressCircle;
  
          private FirebaseStorage mStorage;
          private DatabaseReference mDatabaseRef;
          private ValueEventListener mDBListener;
  
          private List&lt;Upload&gt; mUploads;
          private SwipeRefreshLayout mySwipeRefreshLayout;
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_images);
              mySwipeRefreshLayout = findViewById(R.id.Swipe_Refresh);
              mySwipeRefreshLayout.setOnRefreshListener(
                  new SwipeRefreshLayout.OnRefreshListener() {
                      @Override
                      public void onRefresh() {
                      }
                  }
          );
  
              mRecyclerView = findViewById(R.id.recycler_view);
              mRecyclerView.setHasFixedSize(true);
              mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  
              mProgressCircle = findViewById(R.id.progress_circle);
  
              mUploads = new ArrayList&lt;&gt;();
  
              mAdapter = new ImageAdapter(ImagesActivity.this, mUploads);
  
              mRecyclerView.setAdapter(mAdapter);
  
              mAdapter.setOnItemClickListener(ImagesActivity.this);
  
              mStorage = FirebaseStorage.getInstance();
              mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
  
              mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot) {
  
                      mUploads.clear();
  
                      for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                          Upload upload = postSnapshot.getValue(Upload.class);
                          upload.setKey(postSnapshot.getKey());
                          mUploads.add(upload);
                      }
  
                      mAdapter.notifyDataSetChanged();
  
                      mProgressCircle.setVisibility(View.INVISIBLE);
                  }
  
                  @Override
                  public void onCancelled(DatabaseError databaseError) {
                      Toast.makeText(ImagesActivity.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
                      mProgressCircle.setVisibility(View.INVISIBLE);
                  }
              });
          }
  
          @Override
          public void onItemClick(int position) {
              Toast.makeText(this, "Normal click at position: " + position, Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onWhatEverClick(int position) {
              Toast.makeText(this, "Whatever click at position: " + position, Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onDeleteClick(int position) {
              Upload selectedItem = mUploads.get(position);
              final String selectedKey = selectedItem.getKey();
  
              StorageReference imageRef = mStorage.getReferenceFromUrl(selectedItem.getImageUrl());
              imageRef.delete().addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                  @Override
                  public void onSuccess(Void aVoid) {
                      mDatabaseRef.child(selectedKey).removeValue();
                      Toast.makeText(ImagesActivity.this, "Item deleted", Toast.LENGTH_SHORT).show();
                  }
              });
          }
  
          @Override
          protected void onDestroy() {
              super.onDestroy();
              mDatabaseRef.removeEventListener(mDBListener);
          }
      }
  </code></pre>
  
  <p><strong>ImageAdapter.java</strong>
  This Is My Image Adapter</p>
  
  <pre><code> public class ImageAdapter extends RecyclerView.Adapter&lt;ImageAdapter.ImageViewHolder&gt; {
      private Context mContext;
      private List&lt;Upload&gt; mUploads;
      private OnItemClickListener mListener;
  
      public ImageAdapter(Context context, List&lt;Upload&gt; uploads) {
          mContext = context;
          mUploads = uploads;
      }
  
      @Override
      public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
          return new ImageViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(ImageViewHolder holder, int position) {
          Upload uploadCurrent = mUploads.get(position);
          holder.textViewName.setText(uploadCurrent.getName());
          Picasso.with(mContext)
                  .load(uploadCurrent.getImageUrl())
                  .placeholder(R.mipmap.ic_launcher)
                  .fit()
                  .centerCrop()
                  .into(holder.imageView);
      }
  
      @Override
      public int getItemCount() {
          return mUploads.size();
      }
  
      public class ImageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
              View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener {
          public TextView textViewName;
          public ImageView imageView;
  
          public ImageViewHolder(View itemView) {
              super(itemView);
  
              textViewName = itemView.findViewById(R.id.text_view_name);
              imageView = itemView.findViewById(R.id.image_view_upload);
  
              itemView.setOnClickListener(this);
              itemView.setOnCreateContextMenuListener(this);
          }
  
          @Override
          public void onClick(View v) {
              if (mListener != null) {
                  int position = getAdapterPosition();
                  if (position != RecyclerView.NO_POSITION) {
                      mListener.onItemClick(position);
                  }
              }
          }
  
          @Override
          public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
              menu.setHeaderTitle("Select Action");
              MenuItem doWhatever = menu.add(Menu.NONE, 1, 1, "Do whatever");
              MenuItem delete = menu.add(Menu.NONE, 2, 2, "Delete");
  
              doWhatever.setOnMenuItemClickListener(this);
              delete.setOnMenuItemClickListener(this);
          }
  
          @Override
          public boolean onMenuItemClick(MenuItem item) {
              if (mListener != null) {
                  int position = getAdapterPosition();
                  if (position != RecyclerView.NO_POSITION) {
  
                      switch (item.getItemId()) {
                          case 1:
                              mListener.onWhatEverClick(position);
                              return true;
                          case 2:
                              mListener.onDeleteClick(position);
                              return true;
                      }
                  }
              }
              return false;
          }
      }
  
      public interface OnItemClickListener {
          void onItemClick(int position);
  
          void onWhatEverClick(int position);
  
          void onDeleteClick(int position);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener) {
          mListener = listener;
      }
  }
  
  **Upload.java**
  </code></pre>
  
  <p><strong>This My Upload Class</strong>
          package com.codinginflow.firebaseuploadexample;</p>
  
  <pre><code>import com.google.firebase.database.Exclude;
  
  public class Upload {
      private String mName;
      private String mImageUrl;
      private String mKey;
  
      public Upload() {
          //empty constructor needed
      }
  
      public Upload(String name, String imageUrl) {
          if (name.trim().equals("")) {
              name = "No Name";
          }
  
          mName = name;
          mImageUrl = imageUrl;
      }
  
      public String getName() {
          return mName;
      }
  
      public void setName(String name) {
          mName = name;
      }
  
      public String getImageUrl() {
          return mImageUrl;
      }
  
      public void setImageUrl(String imageUrl) {
          mImageUrl = imageUrl;
      }
  
      @Exclude
      public String getKey() {
          return mKey;
      }
  
      @Exclude
      public void setKey(String key) {
          mKey = key;
      }
  }
  </code></pre>