Reputation: 425
I want to use right to left direction in gridview. By default gridview shows contents left to right.
For example:
If I have this array and I want to specify 3 column for it:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
GridView shows it like this:
[1 2 3]
[4 5 6]
[7 8 9]
but I want to show it like this:
[3 2 1]
[6 5 4]
[9 8 7]
Upvotes: 2
Views: 1518
Reputation: 425
By the suggestion of "Dmytro Danylyk" i use this function and solve my problem.
/** 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;
}
Upvotes: 4
Reputation: 19788
Can`t you just modify your List to match your requirement?
Before
List<String> list = new ArrayList<String>();
list .add("Element 1");
list .add("Element 2");
list .add("Element 3");
After
List<String> list = new ArrayList<String>();
list .add("Element 3");
list .add("Element 2");
list .add("Element 1");
Upvotes: 0