问题
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