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 ?***
}
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.