Skip to content
Advertisement

How to get id data from database deleting – setOnLongClickListener ERROR

I have a recyclerview and sql lite database. I keep city names in SQLite database and display them in recyclerview. When the city is setOnclickListener in the recyclerview, the city’s weather is shown and I do this by taking the city’s id from the sql lite database.

arrayList.get(position).id

it worked in setOnClickListener but it doesnt work setOnLongClickListener

I want to delete the city name in the recyclerview when I longclick but not deleted becasue it doesnt work.

This error appears in logcat : ” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 “ or something like that

How can I solve this issue ?

My Adapter class

JavaScript

Advertisement

Answer

you have in your code

JavaScript

then few lines below

JavaScript

your array list is empty after remove call, but you are still trying to get this item at position, thus you are getting IndexOutOfBoundsException: Index: 0, Size: 0 – you are trying to obtain item at position = 0 and array is empty

try to move obtaining dbId BEFORE removing from array

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement