title: How to delete data in ListView and also from Firebase?
body: <p>I am working on an Android Application that saves the medicine Inventory in Firebase. All Inventory saved on Firebase perfectly.
  The Links i have visited are <a href="https://stackoverflow.com/questions/36185620/how-to-remove-child-nodes-in-firebase-android">this</a> <a href="https://stackoverflow.com/questions/41869606/update-and-delete-data-in-firebase">this</a>
  I showed all inventory in the list in the Android. Now What I want to do is delete the data item from the list by having a button again every list Item.
  Here is my XML code of list view</p>
  
  <pre><code>&lt;LinearLayout
  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:background="@drawable/bgcolor"
  android:layout_height="match_parent"&gt;
  
  &lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="10dp"
      android:background="@drawable/bgcolor"&gt;
  
      &lt;TextView
          android:id="@+id/tvmediname"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_below="@+id/tvname"
          android:layout_marginTop="14dp"
          android:paddingLeft="15dp"
          android:text="Name"
          android:textSize="20sp"
          tools:ignore="UnknownId" /&gt;
  
      &lt;TextView
          android:id="@+id/tvmediusage"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/tvmediname"
          android:layout_alignStart="@+id/tvmediname"
          android:layout_below="@+id/tvmediname"
          android:paddingLeft="15dp"
          android:text="Usage"
          android:textSize="20sp" /&gt;
  
      &lt;TextView
          android:id="@+id/tvmedigenre"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/tvmediname"
          android:layout_alignStart="@+id/tvmediname"
          android:layout_below="@+id/tvmediusage"
          android:paddingLeft="15dp"
          android:text="Company"
          android:textSize="20sp" /&gt;
  
      &lt;TextView
          android:id="@+id/tvexpdate"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_below="@+id/tvmedigenre"
          android:paddingLeft="15dp"
          android:text="Expiry Date"
          android:textSize="20sp" /&gt;
  
      &lt;ImageButton
          android:id="@+id/btndelete"
          android:layout_width="90sp"
          android:layout_height="100sp"
          android:layout_alignParentEnd="true"
          android:layout_alignParentRight="true"
          android:layout_centerVertical="true"
          app:srcCompat="@drawable/btndelt" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is my retrieve activity that Retrieves the data From Firebase </p>
  
  <pre><code>public class RetreiveActivity extends AppCompatActivity {
  ListView mylistView;
  DatabaseReference db;
  List&lt;ClassMedicine&gt; medicineList;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_retreive);
      mylistView= findViewById(R.id.mylist);
      medicineList= new ArrayList&lt;&gt;();
      db= FirebaseDatabase.getInstance().getReference("medicines");
  
  }
  
  @Override
  protected void onStart() {
      super.onStart();
      db.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              medicineList.clear();
              for (DataSnapshot medicineSnapshot:dataSnapshot.getChildren()){
                  ClassMedicine classMedicine=medicineSnapshot.getValue(ClassMedicine.class);
                  medicineList.add(classMedicine);
              }
              MedicineList adapter=new MedicineList(RetreiveActivity.this,medicineList);
              mylistView.setAdapter(adapter);
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is my Model Class </p>
  
  <pre><code>public class ClassMedicine {
  String medicineId;
  String medicineName;
  String medicineUsage;
  String medicineGenre;
  String mediDate;
  
  public ClassMedicine(){
  }
  public ClassMedicine(String medicineId, String medicineName, String medicineUsage, String medicineGenre,String mediDate) {
      this.medicineId = medicineId;
      this.medicineName = medicineName;
      this.mediDate= mediDate;
      this.medicineUsage = medicineUsage;
      this.medicineGenre = medicineGenre;
  }
  
  public String getMedicineId() {
      return medicineId;
  }
  
  public String getMedicineName() {
      return medicineName;
  }
  
  public String getMedicineUsage() {
      return medicineUsage;
  }
  
  public String getMedicineGenre() {
      return medicineGenre;
  }
  public String getMediDate() {
      return mediDate;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is my List Activity </p>
  
  <pre><code>public class MedicineList extends ArrayAdapter&lt;ClassMedicine&gt; {
  private Activity context;
  private List&lt;ClassMedicine&gt; medicineList;
  public MedicineList(Activity context,List&lt;ClassMedicine&gt; medicineList){
      super(context,R.layout.mylistlayout,medicineList);
      this.context=context;
      this.medicineList=medicineList;
  }
  
  @NonNull
  @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
      LayoutInflater inflater= context.getLayoutInflater();
      View listViewItems= inflater.inflate(R.layout.mylistlayout,null,true);
      TextView textViewName=listViewItems.findViewById(R.id.tvmediname);
      TextView textViewGenre=listViewItems.findViewById(R.id.tvmedigenre);
      TextView textViewUsage=listViewItems.findViewById(R.id.tvmediusage);
      TextView textViewDate= listViewItems.findViewById(R.id.tvexpdate);
      ClassMedicine classMedicine= medicineList.get(position);
      textViewName.setText(classMedicine.getMedicineName());
      textViewGenre.setText(classMedicine.getMedicineGenre());
      textViewUsage.setText(classMedicine.getMedicineUsage());
      textViewDate.setText(classMedicine.getMediDate());
      return listViewItems;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I want to do to delete a particular list Item from List. As the list item is deleted that particular data should also remove from the firebase</p>