简体   繁体   中英

How can I get the next Item in a ListView?

Im dealing with Media files. When for example a song ends, I want the ListView to select the next song in the list. So in general I want to get the next Item after the selected Item.

Here is a simple code to how to iterate over the elements in your ListView:

ObservableList<MediaFile> items = listView.getItems();
items.forEach(mediaFile) -> {
    //Custom logic... 
    if (mediaFile.equals(currentMediaFile)) {
    ...
    }
});

I think you can implement a logic from this point on. You can also try using an Iterator over this list in order to find the next element after the currently selected element. Here is a simple tutorial for the iterator: https://www.tutorialspoint.com/java/java_using_iterator.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM