2012-05-08 14 views
2

グリッドビューで右から左の方向を使いたいと思います。デフォルトでは、gridviewは内容を左から右に表示します。私はこの配列を持っていると私はそれのための3列を指定したい場合はグリッドビューで右から左の方向を使用

:たとえば

[1 2 3] 
[4 5 6] 
[7 8 9] 

が、私がしたい:

[1, 2, 3, 4, 5, 6, 7, 8, 9] 

のGridViewはこのようにそれを示していますこれを次のように表示します。

[3 2 1] 
[6 5 4] 
[9 8 7] 

答えて

4

後、私はこの機能を使用すると私の問題を解決します。

/** 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

あなたの要件に合わせてあなたのリストを変更することはできませんか?

List<String> list = new ArrayList<String>(); 
list .add("Element 1"); 
list .add("Element 2"); 
list .add("Element 3"); 

"ドミトロDanylyk" の提案により、

List<String> list = new ArrayList<String>(); 
list .add("Element 3"); 
list .add("Element 2"); 
list .add("Element 1"); 
関連する問題