简体   繁体   English

GWT ComboBox年代顺序

[英]GWT ComboBox Chronological Order

I have the GWT ComboBox widget(ListBox+TextBox) .User can enter some text into this widget or select from the list of previously existing texts by clicking on the dropdown arrow. 我有GWT ComboBox小部件(ListBox + TextBox)。用户可以在此小部件中输入一些文本,也可以通过单击下拉箭头从以前存在的文本列表中进行选择。

So ,i have an ArrayList and when ever a user enters text and clicks the "Search Button" i perform a search if the entered text exists in the ArrayList and if it doesnt exist i add the text to the ArrayList . 因此,我有一个ArrayList,并且只要用户输入文本并单击“搜索按钮”,我都会执行搜索,如果输入的文本存在于ArrayList中,如果不存在,则将文本添加到ArrayList中。

Then later when i need to display the ComboBox in the View, i am iterating through my ArrayList and adding every String in the Arraylist to ComboBox. 然后稍后当我需要在视图中显示ComboBox时,我遍历ArrayList并将Arraylist中的每个字符串添加到ComboBox。

The way the values are displayed in the Combo Box are not in Chronological order.The latest entered text is at the bottom of the ComboBox.How can i make this Chronological? 组合框中显示的值的方式不是按时间顺序排列的。最新输入的文本在组合框的底部。如何设置此时间顺序?

I can reverse the list and add it to my ComboBox.But when a user selects a text which is already existing thats when the problem is.(I can sublist the ArrayList ,push the selected item to the top and make adjustments to the sublist and add it back to the main ArrayList,but i feel its too long and not effective) 我可以反转列表并将其添加到我的ComboBox中。但是当用户选择问题时已经存在的文本时(我可以将ArrayList列出子列表,将所选项目推到顶部并调整子列表,然后将其添加回主ArrayList,但我觉得它太长且无效)

So are there any suggestions with respect to the data structure that i am using(ArrayList)? 那么关于我正在使用的数据结构(ArrayList)有什么建议吗? which could make my task easier? 这可以使我的工作更轻松?

Sorry for being over elaborate but i always feel its better to be than not to. 对不起,我太精打细算了,但总觉得总比没有好。

Does this sample code manage the list of criteria in the way you wanted: 此示例代码是否以您想要的方式管理条件列表:

import java.util.*;
public class ListManager {

public static void main(String[] args) {
    String[] items = {"snow", "rain", "ice", "sleet", "ice", "sunny"};
    List<String> criteriaList = new ArrayList<String>();
    String criteria;
    for (String newCriteria : items) {
        if (criteriaList.remove(newCriteria)) {
            System.out.println(newCriteria + " was in the list already");
        }
        criteriaList.add(0, newCriteria);
        System.out.println();
        System.out.print("List is: ");
        for (String x : criteriaList) {
            System.out.print(x +"  ");
        }
        System.out.println();
    }
}

} }

The output is: 输出为:

List is: snow 清单是:雪

List is: rain snow 清单是:雨雪

List is: ice rain snow 清单是:冰雨雪

List is: sleet ice rain snow 清单是:雨夹雪冰雨雪

ice was in the list already 冰已经在列表中了

List is: ice sleet rain snow 清单是:冰雨夹雪雨雪

List is: sunny ice sleet rain snow 清单是:晴朗的冰雨夹雪雨

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM