How to sort JSONArray by its Tag name with ascending and descending on android.
In my application i have a JSON like the following and need to display the data according
Following code may useful to you.
ArrayList user_array;
Collections.sort(user_array, new Comparator() {
@Override
public int compare(ResultBean data1, ResultBean data2) {
if (data1.getUserId() >= data2.getUserId()) {
return -1;
} else {
return 1;
}
}
});
Your ResultBean
will look like following.
public class ResultBean {
//other methods and declarations...
public int getUserId() {
return userId;
}
}