グリッドビューで右から左の方向を使用したい。デフォルトでは、gridviewはコンテンツを左から右に表示します。
例えば:
この配列があり、3列を指定したい場合:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
GridViewは次のように表示します。
[1 2 3]
[4 5 6]
[7 8 9]
しかし、私はそれをこのように見せたい:
[3 2 1]
[6 5 4]
[9 8 7]
「Dmytro Danylyk」の提案により、この機能を使用して問題を解決しました。
/** 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;
}
要件に合わせてリストを変更することはできませんか?
前
List<String> list = new ArrayList<String>();
list .add("Element 1");
list .add("Element 2");
list .add("Element 3");
後
List<String> list = new ArrayList<String>();
list .add("Element 3");
list .add("Element 2");
list .add("Element 1");