在 GWT 列表框中按字符串查找

spg*_*spg 5 string gwt listbox find

我想通过指定字符串值来查找 GWT 列表框中项目的索引。

例如,如果我有一个包含以下项目的 GWT ListBox:“Randy”、“Bob”和“Helen”,那么1如果我使用参数调用它,我要实现的方法将返回该值"Bob"

从我在 ListBox javadoc 中看到的情况来看,似乎没有任何快速方法可以做到这一点。

有任何想法吗?

提前致谢!

Ara*_*ram 1

我的 TextBox 实现想法并没有提供开箱即用的功能。将所有项目存储在列表中,并按照您希望它们成为 ListBox 一部分的顺序。

List<String> orderedItems=new ArrayList<String>

orderedItems.add(0,"Randy");
orderedItems.add(1,"Bob");
orderedItems.add(2,"Helen");

//adding items in the same order as they are in List is the key
for(String item:items)
{
   lb.addItem(item);
}
Run Code Online (Sandbox Code Playgroud)

然后你可以使用List的indexOf(..)方法找到索引