Is there a way to get a row by its index/position in table, rather than by its id?
For example I have 3 rows with IDs:
Record1
Record2
Record3
Now if I delete the second row using its id, the remaining rows will be like this:
Record1
Record3
Because I’m using ListView position to determine which row in the database to delete, the next time I try to delete second row, I will get exception because row with id 2 doesn’t exist.
So is there a method that can retrieve row by its index in table?
The better route to go will be to fetch the id of the record from the object represented by
ListViewitem and then use that to get the correct record in the database. In yourListView‘sOnItemClickListener, theonItemClickevent takes theAdapterViewas the first argument and the index of the selected item as the second. Get that item from the adapter and cast it to the type it represents.However, if you really want to get the nth record, I believe you can do the following:
Where n is the index you’re after. This also assumes that your results are ordered in the same fashion as they are in your
ListView.