title: How can I hide Delete button from recyclerview, when the file is not exist?
body: <p>Here is my recyclerView Adapter which shows a list from the database, View button is for downloading and the delete button deletes the file from device storage, it works perfectly. But how can I set Visibility of the delete button invisible/gone, if the file does not exist in the device storage.</p>
  
  <pre><code>
      MainActivity mainActivity;
      ArrayList&lt;DownModel&gt; downModels;
  
      public MyAdapter(MainActivity mainActivity, ArrayList&lt;DownModel&gt; downModels) {
          this.mainActivity =mainActivity;
          this.downModels = downModels;
      }
  
      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
  
          LayoutInflater layoutInflater = LayoutInflater.from(mainActivity.getBaseContext());
          View view = layoutInflater.inflate(R.layout.elements, viewGroup, false);
  
          return new MyViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, final int i) {
  
          myViewHolder.mName.setText(downModels.get(i).getName());
          myViewHolder.mDownload.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(myViewHolder.mDownload.getContext(), PdfView.class);
                  intent.putExtra("pdf_url", downModels.get(i).getLink());
                  intent.putExtra("pdf_name",downModels.get(i).getName());
                  myViewHolder.mDownload.getContext().startActivity(intent);
  
              }
          });
          myViewHolder.mDelete.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Context context = myViewHolder.itemView.getContext();
                  String pdfName = downModels.get(i).getName()+".pdf";
                  File file = new File(context.getFilesDir(), pdfName);
                  try {
                      if (file.exists())
                          file.delete();
                      Log.e("file","file"+file.getAbsolutePath());
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
  
      }
  
  
      @Override
      public int getItemCount() {
          return downModels.size();
      }
  
  }
  </code></pre>
  
  <p>RecyclerView</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  FirebaseFirestore db;
  RecyclerView mRecyclerView;
  ArrayList&lt;DownModel&gt; downModelArrayList = new ArrayList&lt;&gt;();
  MyAdapter myAdapter;
  
  
  
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mRecyclerView= findViewById(R.id.recycle);
      mRecyclerView.setHasFixedSize(true);
      mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
      db=FirebaseFirestore.getInstance();
      dataFromFirebase();
  
  }
  
  @Override
  protected void onResume() {
      super.onResume();
      myAdapter.notifyDataSetChanged();
  }
  
  private void dataFromFirebase() {
      if(downModelArrayList.size()&gt;0)
          downModelArrayList.clear();
  
      db.collection("chapter1").orderBy("value")
              .get()
              .addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task) {
                      for(DocumentSnapshot documentSnapshot: Objects.requireNonNull(task.getResult())) {
  
                          DownModel downModel= new DownModel(documentSnapshot.getString("name"),
                                  documentSnapshot.getString("link"));
                          downModelArrayList.add(downModel);
  
                      }
  
                      myAdapter= new MyAdapter(MainActivity.this,downModelArrayList);
                      mRecyclerView.setAdapter(myAdapter);
  
                  }
              })
  
              .addOnFailureListener(new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      Toast.makeText(MainActivity.this, "Error ;-.-;", Toast.LENGTH_SHORT).show();
                  }
              })
      ;
  
  
  }
  </code></pre>
  
  <p>}
  Layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="5dp"
  &gt;
  
      &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
  
              &gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
                  android:layout_marginBottom="5dp"
                  android:layout_marginTop="5dp"&gt;
  
                  &lt;TextView
                      android:id="@+id/name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_gravity="start"
                      android:text="Name"
                      android:textSize="20sp" /&gt;
              &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="5dp"
              android:layout_marginBottom="5dp"
              android:orientation="horizontal"
              android:weightSum="2"
              &gt;
  
              &lt;Button
                  android:id="@+id/down"
                  android:layout_width="0dp"
                  android:layout_height="30dp"
                  android:layout_marginEnd="10dp"
                  android:layout_weight="1"
                  android:background="#A00303"
                  android:elevation="7dp"
                  android:text="View"
                  android:textColor="#FFFFFF"
                  tools:visibility="visible" /&gt;
  
              &lt;Button
                  android:id="@+id/delete"
                  android:layout_width="0dp"
                  android:layout_height="30dp"
                  android:layout_marginStart="10dp"
                  android:layout_weight="1"
                  android:background="#A00303"
                  android:elevation="7dp"
                  android:text="Delete"
                  android:textColor="#FFFFFF"
                  tools:visibility="gone" /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/6JmSU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6JmSU.png" alt="image"></a>  </p>