2015-07-13 19 views
0

我早就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)); 
      } 
     } 
    } 

能不能帮我解决这个问题

+0

我要说的是,在这种情况下_setWidget_应该被称为只有一次的方法,或者是重写,这意味着行和列应是这似乎是不可能的相同相同的图像。你尝试调试吗?我们是否曾经或不叫setWidget? – Rufi

回答

1

这是一个逻辑上的错误在你的for循环。 你总是只覆盖使用的最后一个图像中的元素imageList

你可以尝试这样的事:

int row = 0; 
    int col = 0; 
    for (Image image : imageList) { 
     grid.setWidget(row, col, image); 
     col++; 
     if (col > 2) { 
      col = 0; 
      row++; 
     } 
    } 
相关问题