I have made a jsonarray of jsonobjects. Now I need to sort the JSONArray on base of a value from the jsonobjects. Formerly I sorted ArrayLists of custom objects like this:>
If you are going to display the data contained in the JSONArray
then it may make sense to sort it in the adapter itself. For example, the ArrayAdapter
class already has the requisite methods such as Insert
, Remove
, and of course Sort
.
adapter.sort(new Comparator(){
@Override
public int compare(JSONObject arg0, JSONObject arg1) {
return arg0.optString("SortField", "").compareTo(arg1.optString("SortField","")) ;
}
});