Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting selected element from ListView

I modify a ListView with the results from a database search in order to use that selection to make another DB request later on.

I want to get the field value of that ListView. What method can I use for that?

I just thought I can also add an event to the onclick and keep it on an attribute for the controller. Is that acceptable too?

like image 326
Dynelight Avatar asked Nov 07 '12 06:11

Dynelight


1 Answers

Say with list view like this:

ListView<String> listView =new ListView<String>();

Getting selected element from ListView:

listView.getSelectionModel().getSelectedItem();

Tracking (Listening) the changes in list view selection:

listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
    @Override
    public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
        System.out.println("ListView selection changed from oldValue = " 
                + oldValue + " to newValue = " + newValue);
    }
});
like image 81
Uluk Biy Avatar answered Sep 16 '22 22:09

Uluk Biy