Q:

How to remove a particular list item(list row) within a custom list with custom array adapter?

I am a newbie in android, i am developing an app in which i am scanning NFC card and matching the resultant string of NFC with the values in the list.
So what i want is when a result of NFC matches any of the list item , the matched list item(list row) should be deleted.
Below is the code for the custom list view:
public class Item {
     private String StdName;
     private String Id;
     private int img;

public Item() {

}

public Item(String name, String id, int img) {
    this.StdName = name;
    this.Id = id;
    this.img = img;
}
//getters & setters...
 ...
}

and using a custom array adapter 
 public class ItemAdapter extends ArrayAdapter<Item>

Adding elements to the list as follows:
 private ArrayList<Item> m_parts = new ArrayList<Item>();
 m_parts.add(new Item(StdntId, StudentName, R.drawable.cancel));
 m_adapter = new ItemAdapter(MainActivity.this, R.layout.list_row, m_parts);
 listView.setAdapter(m_adapter);

i need to find out the index of the list item which Id(a field in the list-item) matches the NFC string so that i can delete the list item by index.
The main issue is with comparing the result string e.g "2" with the "id" field in the custom array-list i.e m_parts which is having total 3 fields like (String id, String name, integer img). So i want to match the string which i am getting from sensing the nfc tag with "id" field in m_parts array-list So please help/guide me to achieve the task.
Thanks!!!

A:

You will need to remove that item from your list and then tell the adapter that it has been removed like this:
this.m_parts.remove(position);
notifyItemRemoved(position);

The logic to get your position will vary depending on how the rest of your code works.
To match your Strings just loop through each of your items and see if it matches, if it does, delete/remove it. Something like this:
public void checkAndDeleteMatchingIds(String idToMatch) {
    for (int i = 0; i < m_parts.size(); i++) {
        if (m_parts.get(i).getId().equals(idToMatch)) {
            removePart(i);
        }
    }
}

public void removePart(int position) {
    this.m_parts.remove(position);
    notifyItemRemoved(position);
}

Above code would sit inside your adapter, call checkAndDeleteMatchingIds when you scan.

