Maybe a rhetorical question, but I do not understand how to remove the data from the adapter. For example, create a custom class and insert data from the adapter into it or use a key for removal?

listView.setOnItemLongClickListener (new AdapterView.OnItemLongClickListener () { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { parent.getAdapter ().getItem (position); Object obj = listView.getAdapter ().getItem (position); return false; } }); return v; 
  • make an instance of the adapter field of the class and contact adapter.getItem() directly, but do not get it every time from anywhere - pavlofff

1 answer 1

Do you have some kind of collection or array transferred to the adapter? In the adapter, do you save this data stack to a variable? Make the method getItem in the adapter, let's say you have a collection of data

 public Book getBook(int position) { return data.get(position); } 

And then in the OnLongClickListener listener OnLongClickListener take it so

 Book clickedBook = adapter.getBook(position); 

The variable adapter is your adapter)