如何在ListViewer中选择元素 [英] How to select an element in the ListViewer

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

问题描述

我试图在ListViewer中查找和选择一个元素,我将一个字符串与ListViewer中的每个元素进行比较.

I'm trying to find and select an element in the ListViewer, I compare a string with every element in the ListViewer.

我可以获取元素的索引,但是我不知道如何在Listviewer中选择它.

I can get the index of the element but I don't know how to select it in the Listviewer.

String pattern = elementText.gettext();
String[] listViewerValues = mListViewer.getList().getItems();
List<String> valuesList = Arrays.asList(listViewerValues);  
int index = -1;

for(int i=0; i < valuesList.size(); i++) {
    valuesList.set(i, valuesList.get(i).toLowerCase());
}

index = valuesList.indexOf(pattern);
if(index>-1) 
{
    ***....... what to do here ?*** 
}

推荐答案

您可以使用方法

You can use the method setSelection(ISelection, boolean) to set the selection.

这将选择position处的元素:

mListViewer.setSelection(new StructuredSelection(mListViewer.getElementAt(position)), true);

这篇关于如何在ListViewer中选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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