我已经很久了AarrayList<Image> imageList
。当我尝试将此列表中的每个图像放入网格时,结果我只有最新的图像。
我的代码:
final int columnCount =3; //max images in the row
final int rowCount = (int) Math.ceil((double) data.size()/columnCount);
Grid grid = new Grid(rowCount, columnCount);
for (int i=0; i< imageList.size(); i++) {
for (int row = 0; row < rowCount; row++) {
for (int col = 0; col < columnCount; col++) {
grid.setWidget(row, col, imageList.get(i));
}
}
}
你能帮我解决这个问题
最佳答案
这是 for 循环中的逻辑错误。
您总是只是用 imageList
你可以尝试这样的事情:
int row = 0;
int col = 0;
for (Image image : imageList) {
grid.setWidget(row, col, image);
col++;
if (col > 2) {
col = 0;
row++;
}
}
关于java - 如何将小部件添加到具有最大行元素的网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31378374/