如何设置索引“i”处的项目作为 zk 列表框中的选定项目
我使用 ListModelList 将选项列表添加到 ZK 列表框。接下来,我尝试遍历这些选择列表并找到所需的项目(例如“字符串”)。我需要将此项目(“字符串”)设置为所选项目。
我尝试了下面的代码,但它不起作用。有办法做到这一点吗?
liveListModel = new ListModelList(new AppModelItem [] {
new AppModelItem("String", "string"),
new AppModelItem("Number", "number"),
new AppModelItem("Array", "array")
});
String choice [] = {"String", "Hello", "XYZ" };
Listbox typesList = new Listbox();
typesList.setModel(liveListModel);
for (int i = 0; i < choice.length; i ++) {
if (choice.[i] == typesList.getItemAtIndex(i).getValue().toString());
typesList.setSelectedItem(typesList.getItemAtIndex(i));
}
谢谢, 索尼
I added a list of choices using ListModelList to a ZK listbox. Next, I tried to loop through these list of choices and find a required item (say "String"). I need to set this item ("String") as the selected item.
I tried the code below but it doesn't work. Is there a way to do this ?
liveListModel = new ListModelList(new AppModelItem [] {
new AppModelItem("String", "string"),
new AppModelItem("Number", "number"),
new AppModelItem("Array", "array")
});
String choice [] = {"String", "Hello", "XYZ" };
Listbox typesList = new Listbox();
typesList.setModel(liveListModel);
for (int i = 0; i < choice.length; i ++) {
if (choice.[i] == typesList.getItemAtIndex(i).getValue().toString());
typesList.setSelectedItem(typesList.getItemAtIndex(i));
}
Thanks,
Sony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果此代码是您的原始代码,请复制并粘贴到编辑器中,然后删除 if 表达式后面的分号并使用
equals
测试字符串是否相等。 for 循环应如下所示:如果这仍然不起作用,请添加一些调试代码来检查
getValue()
是否确实返回正确的值:If this code is your original code, copied and pasted to the editor, then remove the semicolon after the if expression and use
equals
to test Strings for equality. The for loop should look like this:If this still doesn't work, add some debug code to check if
getValue()
really returns the correct value: