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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.