0

Hi,

I am creating an app using PhoneGap and I'm having trouble getting the selected id of a listview item when it is long pressed.

I have tried using the JQUeryMobile TapHold event which works but only gets the ID of the listview, not the individual items.

$('#listview').bind('taphold', '> li', function (event) {
    alert($(this).index());
});

I am dynamically creating the list using the code below:

HTML:

<ul data-role="listview" id="listview">  </ul>

JQuery:

for(var i = 0; i<len; i++) {
    var output = '<li><h3> Module Code: ' + results.rows.item(i).module + '</h3>Room: ' +results.rows.item(i).room +'</li>';
            $('#listview').append(output).listview('refresh');
}

Any help is appreciated, thanks!

2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0

Assuming that the $(this).index() is the ListView index, you could do something like:

$(this).find("li.selected-class")

Probably the ListView uses some css class to indicate which item is selected or not. I don't know which class it is, but it shouldn't be hard to figure it out.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.