JeremyC
JeremyC

Reputation: 341

Android sorted listview question

I am having a bit of trouble with android. I have a sorted listview of items retrieved from a database.

This is where I run into the problem. How do you get the actual database row id of the item based upon the listview? I can't use the position of the list view due to it being sorted. Is there a way to retrieve it from CursorAdapter?

Thank you,

Upvotes: 0

Views: 401

Answers (2)

TotoroTotoro
TotoroTotoro

Reputation: 17622

Have you tried

Adapter.getItemId(int position);

See the description in the Android docs.

Upvotes: 1

WindsurferOak
WindsurferOak

Reputation: 4907

One thing you can do is to make your database query to order the results by your sort criteria, so when you get the position of your listview item, you can then lookup your Cursor at that same position and retrieve the correct row id.

Another way, which may help, but I haven't actually tried is to somehow map the row id of the item to the listview item's "tag" property. http://developer.android.com/reference/android/view/View.html#Tags

I hope this helps.

Upvotes: 0

Related Questions