简体   繁体   English

按钮列表的列表为空

[英]List of List of Buttons is empty

I'm working around with GWT. 我正在与GWT合作。

Since I have a SQL db and my queries result set size is unknown I thought it would make sense to use Lists. 由于我有一个SQL数据库,并且查询结果集的大小未知,因此我认为使用列表是有意义的。

Actually I have one list of buttons and a second list of list of buttons. 实际上,我有一个按钮列表和第二个按钮列表。

The reason is because I have one table which stores groups and one which stores the actual data. 原因是因为我有一个存储组的表和一个存储实际数据的表。 Both of them in result should be buttons. 结果两个都应该是按钮。

By clicking on a group button my layout is filled with the data buttons between the group buttons. 通过单击组按钮,我的布局被组按钮之间的数据按钮填充。

Now my db connection isn't ready to use so I wrote a function that fills my lists with fake data. 现在我的数据库连接尚未准备就绪,因此我编写了一个函数,用虚假数据填充列表。 Same for the groups. 组相同。

public void fakeGroupData () {
// Group index 0
    btnGroupList.add(new Button("Group a"));
// Group index 1
    btnGroupList.add(new Button("Group b"));
    ...
}

public void fakeData () {

// Group index 0
    btnDataList.add(new Button("Data 1.1"));
    btnDataList.add(new Button("Data 1.2"));
    btnDataList.add(new Button("Data 1.3"));
    btnDataListList.add(btnDataList);
    btnDataList.clear();

// Group index 1
    btnDataList.add(...
}

Declaration looks like this 声明看起来像这样

List<Button> btnGroupList = new ArrayList<Button>();
List<List<Button>> btnDataListList = new ArrayList<List<Button>>();
List<Button> btnDataList = new ArrayList<Button>();

When trying to get the ButtonList of the ListList the error appears. 尝试获取ListList的ButtonList时,出现错误。

    int grpIndex = Panel.getWidgetIndex(grpBtn);
// grpBtn is equal to (Button)event.getSource() called by btnGroup ClickHandler
    btnDataList.clear()
    btnDataList = btnDataListList.get(grpIndex);
    int loopEnd = btnDataList.size() - 1;

    for (int i = 0; i<=loopEnd; i++) {...

"loopEnd" contains "-1" and nothing happens :(. I tried to debug here, everything seems ok. "grpIndex" has the right index so the the right List is loaded. But why is it empty? When debuggin the fakeData function eclipse shows the right size in the ButtonList. “ loopEnd”包含“ -1”,什么也没发生:(.。 eclipse在ButtonList中显示正确的大小。

Hope you can help me :) 希望你能帮我 :)

btnDataList.clear(); will empty your referenced list objects. 将清空您引用的列表对象。

for each Group index you need a new list. 对于每个组索引,您需要一个新列表。 do like this 像这样

btnDataList = new ArrayList<Button>(); instead of btnDataList.clear(); 而不是btnDataList.clear();

// Group index 0
btnDataList.add(new Button("Data 1.1"));
btnDataList.add(new Button("Data 1.2"));
btnDataListList.add(btnDataList);

// Group index 1
btnDataList = new ArrayList<Button>();
btnDataList.add(new Button("Data 2.1"));
btnDataList.add(new Button("Data 2.2"));
btnDataListList.add(btnDataList);

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

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