thunderousNinja
thunderousNinja

Reputation: 3520

Using Cursors and ListView Question

I am stuck on this! I have a listView populated by a a cursor. My question is how can i get the specific item information from the cursor when a certain position in the listview is selected. For example, i select the third index in the listView, I want the information associated with that index from the cursor. How can I do that? Thanks in advance

Upvotes: 0

Views: 305

Answers (2)

Rasel
Rasel

Reputation: 15477

You are creating listview from cursor.So i am assuming that your list item 0 comes from Cursor's first record and so on.So if you click list item at position 3 you can move to cursor corresponding position by cursor.moveToPosition(3).Then can work accordingly

Upvotes: 1

citizen conn
citizen conn

Reputation: 15390

Implement the onListItemClicked() method like so:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    yourCursor.moveToPosition(position);
    yourRowId = yourCursor.getLong(0);
}

Your Activity must extend ListActivity for this to work as expected, like so:

public class YourActivity extends ListActivity {

Upvotes: 1

Related Questions