title: deletes everything from the database,the getRef() method does not work because i cant put my dialog inside the FirebaseRecyclerAdapter
body: <p>RETRIEVADATA CLASS</p>
  <p>package com.dikolobe.salesagent;</p>
  <p>public class RetrieveData extends AppCompatActivity implements View.OnClickListener,OnNoteClickListener{</p>
  <p>private static final String TAG = &quot;&quot;;</p>
  <pre><code>private FirebaseRecyclerAdapter&lt;Product, ViewHolder&gt; firebaseRecyclerAdapter;
  
  //FirebaseRecyclerAdapter adapter;
  
  FirebaseDatabase mDatabase;
  
  DatabaseReference mRef;
  
  FirebaseStorage mStorage;
  
  ItemsAdapter itemsAdapter;
  
  List&lt;Product&gt; productList=new ArrayList&lt;&gt;();
  
  RecyclerView recyclerView;
  
  TextView phone_num;
  
  ViewHolder viewHolder;
  
  private static final int PERMISSION_REQUEST_CODE = 1;
  
  ImageView img;
  
  OnNoteClickListener onNoteClickListener;
  
  Context context;
  
  private List&lt;Product&gt; listItems= new ArrayList&lt;&gt;();
  
  private List&lt;Product&gt; listItemsFull;
  
  public ArrayList&lt;Product&gt; filterList = new ArrayList&lt;&gt;();
  
  private int progressStatus = 0;
  
  private Handler handler = new Handler();
  
  String imageUrl = null;
  
  SearchView searchView;
  
  //ImageView delete;
  
  String productId;
  
  String image;
  
  @Override
  
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_retrieve_data);
  
     // delete =findViewById(R.id.delete);
  
      if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.M) {
  
          if (checkSelfPermission(Manifest.permission.SEND_SMS)
  
                  == PackageManager.PERMISSION_DENIED) {
  
              Log.d(&quot;permission&quot;, &quot;permission denied to SEND_SMS - requesting it&quot;);
  
              String[] permissions = {Manifest.permission.SEND_SMS};
  
              requestPermissions(permissions, PERMISSION_REQUEST_CODE);
  
          }
  
      }
  
      searchView=findViewById(R.id.search);
  
      FirebaseRecyclerOptions&lt;Product&gt; options = new FirebaseRecyclerOptions.Builder&lt;Product&gt;()
  
              .setQuery(FirebaseDatabase.getInstance().getReference()
  
                      .child(&quot;Items&quot;),Product.class)
  
              .build();
  
      mDatabase = FirebaseDatabase.getInstance();
  
      mRef = mDatabase.getReference().child(&quot;Items&quot;);
  
      mStorage = FirebaseStorage.getInstance();
  
      recyclerView = findViewById(R.id.recyclerview_id);
  
      recyclerView.setHasFixedSize(true);
  
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
      productList = new ArrayList&lt;Product&gt;();
  
      itemsAdapter = new ItemsAdapter(RetrieveData.this, productList,this,options);
  
      recyclerView.setAdapter(itemsAdapter);
  
      mRef.addChildEventListener(new ChildEventListener() {
  
          @Override
  
          public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
              Product product = dataSnapshot.getValue(Product.class);
  
              productList.add(product);
  
              itemsAdapter.notifyDataSetChanged();
  
          }
  
          @Override
  
          public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
          }
  
          @Override
  
          public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
  
          }
  
          @Override
  
          public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
  
          }
  
          @Override
  
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
  
      });
  
  }
  
  @Override
  
  protected void onStart(){
  
      super.onStart();
  
      FirebaseRecyclerOptions&lt;Product&gt; options = new FirebaseRecyclerOptions.Builder&lt;Product&gt;()
  
              .setQuery(FirebaseDatabase.getInstance()
  
                      .getReference().child(&quot;Items&quot;), Product.class)
  
                              .build();
  
      firebaseRecyclerAdapter = new FirebaseRecyclerAdapter&lt;Product, ViewHolder&gt;(options) {
  
          @Override
  
          protected void onBindViewHolder(@NonNull com.dikolobe.salesagent.ViewHolder holder, final int 
  </code></pre>
  <p>position, @NonNull Product product) {</p>
  <pre><code>        }
  
          @NonNull
  
          @Override
  
          public com.dikolobe.salesagent.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int 
  </code></pre>
  <p>viewType) {</p>
  <pre><code>            View view = LayoutInflater.from(parent.getContext())
  
                      .inflate(R.layout.design_row_for_recyclerview, parent, false);
  
              return new com.dikolobe.salesagent.ViewHolder(view,onNoteClickListener);
  
          }
  
          public void deleteProduct(int position) {
  
              try{
  
                  FirebaseDatabase.getInstance().getReference().child(&quot;Items&quot;)
  
                          .child(getRef(position).getKey())
  
                          .removeValue().addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
  
                      @Override
  
                      public void onComplete(@NonNull Task&lt;Void&gt; task) {
  
                          Toast.makeText(context,&quot;Deleted succesfully&quot;,Toast.LENGTH_SHORT).show();
  
                      }
  
                  });
  
              }
  
              catch (Exception e){
  
                  Log.e(&quot;error&quot;, e.getMessage());
  
              }
  
          }
  
  
      };
  
      firebaseRecyclerAdapter.startListening();
  
      recyclerView.setAdapter(firebaseRecyclerAdapter);
  
  
  }
  </code></pre>
  <p>@Override</p>
  <p>protected void onStop() {</p>
  <pre><code>super.onStop();
  </code></pre>
  <p>firebaseRecyclerAdapter.stopListening();</p>
  <p>}</p>
  <pre><code>@Override
  </code></pre>
  <p>public boolean onCreateOptionsMenu(Menu menu) {</p>
  <pre><code>MenuInflater menuInflater = getMenuInflater();
  
  menuInflater.inflate(R.menu.menu, menu);
  
  MenuItem menuItem=menu.findItem(R.id.search);
  
  SearchView searchView=(SearchView) menuItem.getActionView();
  
  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
  
      @Override
  
      public boolean onQueryTextSubmit(String query) {
  
          search_product(query);
  
        // itemsAdapter.getFilter().filter(query);
  
          return false;
  
      }
  
  
  
      @Override
  
        public boolean onQueryTextChange(String newText) {
  
            search_product(newText);
  
           //itemsAdapter.getFilter().filter(newText.toString());
  
            return false;
  
        }
  
    });
  
    return true;
  </code></pre>
  <p>}</p>
  <p>@Override</p>
  <p>public boolean onOptionsItemSelected(MenuItem item) {</p>
  <pre><code>  if (item.getItemId() == R.id.add_product) {
  
  
  
        startActivity(new Intent(this, MainActivity.class));
  
  
  
        Toast.makeText(this, &quot;post a product&quot;, Toast.LENGTH_SHORT).show();
  
    } else if (item.getItemId() == R.id.tutorial) {
  
        // startActivity(new Intent(this, AddRider.class));
  
  
  
        //  Toast.makeText(this,&quot;Add a rider to an Event&quot;,Toast.LENGTH_SHORT).show();
  
  
  
    } else if (item.getItemId() == R.id.logOut) {
  
        startActivity(new Intent(this, MainActivity.class));
  
  
  
        Toast.makeText(this, &quot;bye&quot;, Toast.LENGTH_SHORT).show();
  
  
  
    }
  
    return super.onOptionsItemSelected(item);
  </code></pre>
  <p>}</p>
  <p>ItemTouchHelper.SimpleCallback simpleCallback=new</p>
  <p>ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT) {</p>
  <pre><code>  @Override
  
  
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, Re
  </code></pre>
  <p>cyclerView.ViewHolder target) {</p>
  <pre><code>      return false;
  
      }
  
  
  
      @Override
  
      public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
  
  
  
          removeItem((long) viewHolder.itemView.getTag());
  
          productList.remove(viewHolder.getAdapterPosition());
  
          itemsAdapter.notifyDataSetChanged();
  
  
  
      }
  
  
  
      private void removeItem(long id) {
  
      }
  
  };
  
  
  
  
  
      private boolean updateItem(String seller, String description, String price,String location,String 
  </code></pre>
  <p>phone,String productId,String image,String posted_date) {</p>
  <pre><code>        //getting the specified product reference
  
          DatabaseReference dR = FirebaseDatabase.getInstance().getReference(&quot;Items&quot;).child(productId);
  
  
  
          //updating product
  
          Product product = new Product(productId, seller, 
  </code></pre>
  <p>description,price,phone,location,image,posted_date);</p>
  <pre><code>        dR.setValue(product);
  
          Toast.makeText(getApplicationContext(), &quot;Product Updated&quot;, Toast.LENGTH_LONG).show();
  
          return true;
  
      }
  
  
  
  
  
  @Override
  
  public void onNoteClick(final int position) {
  
  
  
      CharSequence[] items = {&quot;Update&quot;, &quot;Delete&quot;};
  
      AlertDialog.Builder dialog = new AlertDialog.Builder(RetrieveData.this);
  
      dialog.setTitle(&quot;Choose Action&quot;);
  
  
              dialog.setItems(items, new DialogInterface.OnClickListener() {
  
          @Override
  
          public void onClick(DialogInterface dialogInterface, int i) {
  
              if(i == 0){
  
  
  
                  Intent update_activty = new Intent(getApplicationContext(),Update_Product.class);
  
                  startActivity(update_activty);
  
  
  
              }
  
              if (i==1){
  
                  Product product=productList.get(position);
  
                  productId =product.getProductId();
  
                  image =product.getImage();
  
  
  
                      final AlertDialog.Builder dialogdelete = new 
  </code></pre>
  <p>AlertDialog.Builder(RetrieveData.this);</p>
  <pre><code>                    dialogdelete.setTitle(&quot;Warning&quot;);
  
                      dialogdelete.setMessage(&quot;Are You Sure You Want to Delete?&quot;);
  
  
                      dialogdelete.setPositiveButton(&quot;OK&quot;, new DialogInterface.OnClickListener() {
  
  
                          @Override
  
                          public void onClick(DialogInterface dialogInterface, int i) {
  
  
  
                              Query mQuery = mRef.orderByChild(&quot;productId&quot;).equalTo(productId);
  
  
                              mQuery.addListenerForSingleValueEvent(new ValueEventListener() {
  
                                  @Override
  
                                  public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
                                      for(DataSnapshot ds: dataSnapshot.getChildren()){
  
                                          ds.getRef().removeValue();
  
                                      }
  
                                      
  </code></pre>
  <p>Toast.makeText(RetrieveData.this,&quot;deleted..!&quot;,Toast.LENGTH_SHORT).show();</p>
  <pre><code>                                }
  
  
  
                                  @Override
  
                                  public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                      
  </code></pre>
  <p>Toast.makeText(RetrieveData.this,databaseError.getMessage(),Toast.LENGTH_SHORT).show();</p>
  <pre><code>                                }
  
                              });
  
  
  
                             Query mPictureReference = 
  </code></pre>
  <p>FirebaseDatabase.getInstance().getReference(&quot;Items&quot;).orderByChild(&quot;image&quot;).equalTo(image);</p>
  <pre><code>                            mPictureReference.getRef().removeValue().addOnSuccessListener(new 
  </code></pre>
  <p>OnSuccessListener() {
  @Override</p>
  <pre><code>                                public void onSuccess(Void aVoid) {
  
                                      Toast.makeText(RetrieveData.this,&quot;Image 
  </code></pre>
  <p>deleted&quot;,Toast.LENGTH_SHORT).show();</p>
  <pre><code>                                }
  
                              }).addOnFailureListener(new OnFailureListener() {
  
                                  @Override
  
                                  public void onFailure(@NonNull Exception e) {
  
                                      Toast.makeText(RetrieveData.this,e.getMessage(),Toast.LENGTH_SHORT).show();
  
                                  }
  
                              });
  
                          }
  
                      });
  
                      dialogdelete.setNegativeButton(&quot;Cancel&quot;, new DialogInterface.OnClickListener() {
  
                          @Override
  
                          public void onClick(DialogInterface dialogInterface, int i) {
  
                              dialogInterface.dismiss();
  
                          }
  
                      });
  
                      dialogdelete.show();
  
  
  
              }
  
  
  
          }
  
  
  
      });
  
      dialog.show();
  
  
  
      // Toast.makeText(getApplicationContext(),&quot;cliked&quot;,Toast.LENGTH_SHORT).show();
  
  
  
  }
  
  
  
  @Override
  
  public void onClick(View v) {
  
  
  
  }
  
  
  
  public static String getTimeDate(long timestamp){
  
      try{
  
          DateFormat dateFormat = getDateTimeInstance();
  
          Date netDate = (new Date(timestamp));
  
          return dateFormat.format(netDate);
  
      } catch(Exception e) {
  
          return &quot;date&quot;;
  
      }
  
  }
  </code></pre>
  <p>}</p>
  <p>ADAPTER CLASS</p>
  <p>package com.dikolobe.salesagent;</p>
  <p>public class ItemsAdapter extends RecyclerView.Adapter implements Filterable {</p>
  <pre><code>public ArrayList&lt;Product&gt; filterList = new ArrayList&lt;&gt;();
  
  private int progressStatus = 0;
  
  
  private Handler handler = new Handler();
  
  private OnNoteClickListener onNoteClickListener;
  
  Context context;
  
  private List&lt;Product&gt; listItems;
  
  private List&lt;Product&gt; listItemsFull;
  
  private Product product;
  
  FirebaseRecyclerOptions&lt;Product&gt; options;
  
  
  
  String imageUrl = null;
  
  
  
  public ItemsAdapter(Context context, List&lt;Product&gt; listItems,OnNoteClickListener 
  </code></pre>
  <p>onNoteClickListener,FirebaseRecyclerOptions options) {</p>
  <pre><code>    this.context = context;
  
  
      this.listItems = listItems;
  
      listItemsFull = new ArrayList&lt;&gt;(listItems);
  
      this.onNoteClickListener = onNoteClickListener;
  
      this.options=options;
  
  }
  
  
  
  public ItemsAdapter(FirebaseRecyclerOptions&lt;Product&gt; options) {
  
  }
  
  
  
  
  
  @NonNull
  
  
  @Override
  
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
  
      View v = 
  </code></pre>
  <p>LayoutInflater.from(parent.getContext()).inflate(R.layout.design_row_for_recyclerview,parent,false);</p>
  <pre><code>    return new ViewHolder(v,onNoteClickListener);
  
  }
  
  @Override
  
  public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
  
  
  
      product = listItems.get(position);
  
      holder.seller.setText(listItems.get(position).getSeller());
  
      holder.desc.setText(listItems.get(position).getDescription());
  
      holder.price.setText(listItems.get(position).getPrice());
  
      holder.location.setText(listItems.get(position).getLocation());
  
      holder.phone.setText(listItems.get(position).getPhone());
  
      holder.time.setText((CharSequence) listItems.get(position).getPosted_date());
  
  
  
      holder.progress_Bar = new ProgressBar(context);
  
      
  
      new Thread(new Runnable() {
  
          public void run() {
  
  
              while (progressStatus &lt; 100) {
  
                  progressStatus += 1;
  
                  handler.post(new Runnable() {
  
                      public void run() {
  
                          holder.progressBar.setProgress(progressStatus);
  
                          holder.textView.setText(progressStatus+&quot;/&quot;+holder.progressBar.getMax());
  
                      }
  
                  });
  
                  try {
  
                      Thread.sleep(200);
  
                  } catch (InterruptedException e) {
  
                      e.printStackTrace();
  
                  }
  
              }
  
          }
  
      }).start();
  
  
  
  
  
      imageUrl = product.getImage();
  
      Picasso.get().load(imageUrl).into(holder.imageView, new Callback() {
  
          @Override
  
          public void onSuccess() {
  
              holder.image_layout.setVisibility(View.INVISIBLE);
  
          }
  
  
  
          @Override
  
          public void onError(Exception e) {
  
              Toast.makeText(context, &quot;&quot; + e.getMessage(), Toast.LENGTH_SHORT).show();
  
          }
  
      });
  
      holder.phone.setOnClickListener(new View.OnClickListener() {
  
          @Override
  
          public void onClick(View v) {
  
  
  
              int id=v.getId();
  
              if (id==R.id.phoneTv){
  
  
  
                  String phoneNumber = product.getPhone();
  
                  String message = &quot;I am interested&quot;;
  
                  SmsManager smsManager = SmsManager.getDefault();
  
                  smsManager.sendTextMessage(phoneNumber, null, message, null, null);
  
                  Toast.makeText(context,&quot;Interest message sent successfully&quot;, 
  </code></pre>
  <p>Toast.LENGTH_LONG).show();</p>
  <pre><code>            }
  
  
  
  
  
          }
  
      });
  
      holder.call.setOnClickListener(new View.OnClickListener() {
  
          @Override
  
          public void onClick(View v) {
  
              int id=v.getId();
  
              if(id==R.id.call){
  
  
  
                  String phoneNumber = product.getPhone();
  
                  Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(&quot;tel:&quot;+phoneNumber));
  
                  context.startActivity(intent);
  
              }
  
          }
  
      });    }
  
  
  @Override
  
  public int getItemCount() {
  
      return listItems.size();
  
  }
  
  
  
  @Override
  public Filter getFilter() {
  
      return filterProducts;
  }
  
  private Filter filterProducts = new Filter() {
  
      @Override
  
      protected FilterResults performFiltering(CharSequence constraint) {
  
          ///*to delete*/String search_text = constraint.toString().toLowerCase();
  
          List&lt;Product&gt; productFiltrate = new ArrayList&lt;&gt;();
  
          if (constraint.length()==0 ){
  
              productFiltrate.addAll(listItemsFull);
  
          }else
  
          {
  
              String pattern = constraint.toString().toLowerCase().trim();
  
              for (Product product:listItemsFull){
  
                  if(product.getSeller().toLowerCase().contains(pattern)){
  
                      productFiltrate.add(product);
  
                  }
  
              }
  
          }
  
          FilterResults filterResults = new FilterResults();
  
          filterResults.values = productFiltrate;
  
          return filterResults;
  
      }
  
  
  
      @Override
  
      protected void publishResults(CharSequence constraint, FilterResults results) {
  
          filterList.clear();
  
          filterList.addAll((List) results.values);
  
          notifyDataSetChanged();
  
      }
  
  };
  </code></pre>
  <p>}</p>
  <p>INSERT DATA/MAIN_ACTIVITY</p>
  <p>package com.dikolobe.salesagent;</p>
  <p>public class MainActivity extends AppCompatActivity {</p>
  <pre><code>FirebaseRecyclerAdapter firebaseRecyclerAdapter;
  </code></pre>
  <p>ItemsAdapter itemsAdapter;</p>
  <pre><code>FirebaseDatabase mDatabase;
  
  DatabaseReference mRef;
  
  FirebaseStorage mStorage;
  
  EditText seller_name,desc,price,location,phone;
  
  Button btnInsert,list;
  
  ImageButton imageButton,take_Photo;
  
  ProgressBar progressBar;
  
  private ProgressDialog mProgress;
  
  Uri imageUri = null;
  
  final int REQUEST_CODE_IMAGE=999;
  
  static final int REQUEST_IMAGE_CAPTURE = 1;
  
  private int progressStatus = 0;
  
  private TextView textView;
  
  private Handler handler = new Handler();
  
  ViewHolder holder;
  
  FrameLayout image_layout;
  
  
  @Override
  
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_main);
  
  
      seller_name = findViewById(R.id.seller_nameEt);
  
      desc = findViewById(R.id.descEt);
  
      price = findViewById(R.id.priceEt);
  
      location = findViewById(R.id.locationEt);
  
      phone = findViewById(R.id.phoneEt);
  
      btnInsert = findViewById(R.id.save);
  
      //list = findViewById(R.id.list);
  
      imageButton = findViewById(R.id.imageButton);
  
      progressBar = (ProgressBar) findViewById(R.id.progressBar);
  
      textView = (TextView) findViewById(R.id.textView);
  
      image_layout = (FrameLayout) findViewById(R.id.layout_image);
  
      take_Photo = (ImageButton) findViewById(R.id.take_pic);
  
      take_Photo.setOnClickListener(new View.OnClickListener() {
  
          @Override
  
          public void onClick(View v) {
  
              int id = v.getId();
  
              if (id==R.id.take_pic){
  
                  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
                  startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
  
              }
  
          }
  
      });
  
  
  
      mDatabase = FirebaseDatabase.getInstance();
  
      mRef = mDatabase.getReference().child(&quot;Items&quot;);
  
      mStorage = FirebaseStorage.getInstance();
  
  
  
      imageButton.setOnClickListener(new View.OnClickListener() {
  
          @Override
  
          public void onClick(View v) {
  
              ActivityCompat.requestPermissions(MainActivity.this,
  
                      new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE_IMAGE);
  
          }
  
      });
  
      progressBar = new ProgressBar(MainActivity.this);
  
      image_layout.setVisibility(View.INVISIBLE);
  
      btnInsert.setOnClickListener(new View.OnClickListener() {
  
  
  
          @Override
  
          public void onClick(View v) {
  
  
  
              image_layout.setVisibility(View.VISIBLE);
  
              new Thread(new Runnable() {
  
                  public void run() {
  
                      while (progressStatus &lt; 100) {
  
                          progressStatus += 1;
  
                          // Update the progress bar and display the
  
                          //current value in the text view
  
                          handler.post(new Runnable() {
  
                              public void run() {
  
                                  progressBar.setProgress(progressStatus);
  
                                  textView.setText(progressStatus+&quot;/&quot;+progressBar.getMax());
  
                              }
  
                          });
  
                          try {
  
                              // Sleep for 200 milliseconds.
  
                              Thread.sleep(200);
  
                          } catch (InterruptedException e) {
  
                              e.printStackTrace();
  
                          }
  
                      }
                  }
  
              }).start();
  
  
  
              final String seller = seller_name.getText().toString().trim();
  
              final String fn = desc.getText().toString().trim();
  
              final String ln = price.getText().toString().trim();
  
              final String place = location.getText().toString().trim();
  
              final String phon = phone.getText().toString().trim();
  
              final String id = mRef.push().getKey();
  
  
  
              if (!(seller.isEmpty() &amp;&amp; fn.isEmpty() &amp;&amp; ln.isEmpty() &amp;&amp; place.isEmpty() &amp;&amp; 
  </code></pre>
  <p>phon.isEmpty() &amp;&amp; imageUri!=null)){</p>
  <pre><code>                StorageReference filepath = 
  </code></pre>
  <p>mStorage.getReference().child(&quot;images&quot;).child(imageUri.getLastPathSegment());</p>
  <pre><code>                filepath.putFile(imageUri).addOnSuccessListener(new 
  </code></pre>
  <p>OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {</p>
  <pre><code>                    @Override
  
                      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  
  
                          image_layout.setVisibility(View.INVISIBLE);
  
                          Task&lt;Uri&gt; downloadUrl = 
  </code></pre>
  <p>taskSnapshot.getStorage().getDownloadUrl().addOnCompleteListener(new OnCompleteListener() {</p>
  <pre><code>                            @Override
  
                              public void onComplete(@NonNull Task&lt;Uri&gt; task) {
  
                                  String t=task.getResult().toString();
  
                                  final DatabaseReference newPost=mRef.push();
  
                                  newPost.child(&quot;seller&quot;).setValue(seller);
  
  
                                  newPost.child(&quot;description&quot;).setValue(fn);
  
                                  newPost.child(&quot;price&quot;).setValue(ln);
  
                                  newPost.child(&quot;location&quot;).setValue(place);
  
                                  newPost.child(&quot;phone&quot;).setValue(phon);
  
                                  newPost.child(&quot;productId&quot;).setValue(id);
  
                                  newPost.child(&quot;image&quot;).setValue(task.getResult().toString());
  
  
  
                                  DateFormat dateFormat = new SimpleDateFormat(&quot;yyyy/MM/dd HH:mm:ss&quot;);
  
                                  Date date = new Date();
  
                                  String strDate = dateFormat.format(date).toString();
  
                                  newPost.child(&quot;posted_date&quot;).setValue(strDate);
  
                                  Toast.makeText(MainActivity.this,&quot;successfully uploaded&quot;, 
  </code></pre>
  <p>Toast.LENGTH_SHORT).show();</p>
  <pre><code>                                seller_name.setText(&quot;&quot;);
  
                                  desc.setText(&quot;&quot;);
  
                                  price.setText(&quot;&quot;);
  
                                  location.setText(&quot;&quot;);
  
                                  phone.setText(&quot;&quot;);
  
                                  imageButton.setImageURI(null);
  
                                  goToRetrieveDataClass();
  
                              }
  
  
  
                          }).addOnFailureListener(new OnFailureListener() {
  
                              @Override
  
                              public void onFailure(@NonNull Exception e) {
  
                                  Toast.makeText(getApplicationContext(),&quot;Failed to 
  </code></pre>
  <p>upload..!&quot;,Toast.LENGTH_LONG).show();</p>
  <pre><code>                            }
  
                          });
  
  
                      }
  
                  });
  
              }else Toast.makeText(MainActivity.this,&quot;Please write all your 
  </code></pre>
  <p>details..!&quot;,Toast.LENGTH_LONG).show();</p>
  <pre><code>        }
  
  
  
      });
  
  
  
      if (!hasCamera())
  
          take_Photo.setEnabled(false);
  
  }
  
  
  
  @Override
  
  protected void onStart() {
  
      super.onStart();
  
     // firebaseRecyclerAdapter.startListening();
  
  }
  
  @Override
  
  protected void onStop() {
  
      super.onStop();
  
     // firebaseRecyclerAdapter.stopListening();
  
  }
  
  private Boolean hasCamera() {
  
      return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
  
  }
  
  
  
  public void launchCamera(View view) {
  
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
      startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
  
  }
  
  
  
  @Override
  
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] 
  </code></pre>
  <p>grantResults) {</p>
  <pre><code>    if (requestCode == REQUEST_CODE_IMAGE) {
  
          if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  
              Intent gallery = new Intent(Intent.ACTION_GET_CONTENT);
  
              gallery.setType(&quot;image/*&quot;);
  
              startActivityForResult(gallery, REQUEST_CODE_IMAGE);
  
          } else {
  
              Toast.makeText(this, &quot;no permission&quot;, Toast.LENGTH_SHORT).show();
  
          }
  
          return;
  
      }
  
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  
  
  
  }
  
  @Override
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
  
      if (requestCode == REQUEST_CODE_IMAGE &amp;&amp; resultCode == RESULT_OK) {
  
  
          imageUri = data.getData();
  
          CropImage.activity(imageUri).setGuidelines(CropImageView.Guidelines.ON)
  
                  .setAspectRatio(1,1).start(this);
  
  
          imageButton.setImageURI(imageUri);
  
  
      }
  
      if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
  
          CropImage.ActivityResult result = CropImage.getActivityResult(data);
  
          if(resultCode == RESULT_OK){
  
          }
  
          else if(resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE){
  
              Exception error = result.getError();
  
  
  
          }
  
      }
  
      super.onActivityResult(requestCode, resultCode,data);
  
  }
  </code></pre>
  <p>}</p>