如何在ListViewer中选择元素 [英] How to select an element in the ListViewer
本文介绍了如何在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屋!
查看全文