从ListView获取选定的元素 [英] Getting selected element from ListView

查看:92
本文介绍了从ListView获取选定的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用数据库搜索的结果修改了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.

我想获取该ListView的字段值.我可以使用哪种方法?

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

我只是想我也可以将事件添加到onclick并将其保留在控制器的属性上.也可以接受吗?

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?

推荐答案

对列表视图这样说:

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

从ListView获取所选元素:

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);
    }
});

这篇关于从ListView获取选定的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆