2010-12-04 80 views

回答

3

我寫了這一點。我認爲解決您的問題

/** Returns inverted list by step that take. for example if our list is {1, 2, 3, 4, 5, 6, 
    * 7 ,8 ,9} and step is 3 inverted list is this: {3, 2, 1, 6, 5, 4, 9, 8, 7} 
    */ 
     public static <E> ArrayList<E> invert(List<E> source, int step){ 
      List<E> inverted = new ArrayList<E>(); 
      for(int i = 0; i < source.size(); i++){ 
       if((i + 1) % step == 0){ 
        for(int j = i, count = 0; count < step; j--, count++){ 
         inverted.add(source.get(j)); 
        } 
       } 
      } 

      // 
      // When (source.size() % step) is not 0 acts.this is for last of list. add last part 
      // of the source that wasn't add. 
      // 
      int remainder = source.size() % step; 
      if((remainder) != 0){ 
       for (int j = source.size() - 1, count = 0; count < (remainder); j--, count++) { 
        inverted.add(source.get(j)); 
       } 
      } 

      return (ArrayList<E>) inverted; 

     } 
+0

我會檢查它..感謝 – 2012-05-11 09:54:33

1

我想唯一的方法是創建一個自定義gridview,覆蓋onLayout()方法。 看一看here

或者你可以反轉列表適配器中每一行的項目?像一個三列格,而不是

[1 2 3][4 5 6][7 8] --> 
[3 2 1][6 5 4][null 8 7]. 

,(我承認我從來沒有使用過的GridView)

1

我臉上有同樣的問題,但最後用復位陣列 解決這裏只更改u [R column no = 3

ArrayList<String> tb_ith_sections_list = new ArrayList<String>; 
tb_ith_sections_list = dbhelper.getArrayList(); 
     int sectionCount = tb_ith_sections_list.size(); 
       if(sectionCount > 0){ 
        int rowCount =sectionCount/4; 
        int colCount ; 
        if(sectionCount > 4){ 
         colCount=4; 
        }else{ 
         colCount = sectionCount; 
        } 
        if(colCount>sectionCount){ 
         colCount=sectionCount; 
        } 
        int k=colCount; 
        int m=0; 
        for(int j=0;j<rowCount;j++){ 
         m=(j*colCount); 
         k=m+colCount; 
         if(k>sectionCount){ 
          k=(sectionCount-(j*colCount)); 
         } 
         for(int i=m;i<k;i++){ 
          TB_IVN_SECTIONS tb_Temp=new TB_IVN_SECTIONS(); 
          TB_IVN_SECTIONS tb_ithFirst=tb_ith_sections_list.get(i); 
          TB_IVN_SECTIONS tb_ithSecond= tb_ith_sections_list.get(k-1); 
          tb_Temp=tb_ithFirst; 
          tb_ith_sections_list.set(i, tb_ithSecond); 
          tb_ith_sections_list.set(k-1,tb_ithFirst); 
          k--; 
         }    
        }