How to select an element in the ListViewer

↘锁芯ラ 提交于 2019-12-11 02:23:44

问题


I'm trying to find and select an element in the ListViewer, I compare a string with every element in the 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 ?*** 
}

回答1:


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

This will select the element at position:

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


来源:https://stackoverflow.com/questions/12799029/how-to-select-an-element-in-the-listviewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!