Getting selected element from ListView

前端 未结 3 732
别跟我提以往
别跟我提以往 2021-01-01 17:31

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

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 17:43

    Say with list view like this:

    ListView listView =new ListView();
    

    Getting selected element from ListView:

    listView.getSelectionModel().getSelectedItem();
    

    Tracking (Listening) the changes in list view selection:

    listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observable, String oldValue, String newValue) {
            System.out.println("ListView selection changed from oldValue = " 
                    + oldValue + " to newValue = " + newValue);
        }
    });
    

提交回复
热议问题