1

I am using a Json object array list for displaying data. Now I want to use an expandable listview in which the data is classified according to date in the object. how to classify the child list according to the date.

The json object consists of a pick up date and passenger details. I want to sort and make an expandable list view consisting of date in the main list and passenger details in the sub-list sorted according to the date.

Some objects have the same booking date, so they need to be clubbed under one.

This is the json object:

Vaisakh Vinod
  • 267
  • 2
  • 14

2 Answers2

0

I am not completely sure what you are asking, but if you are trying to sort an array of JSON objects of the following form: [{},{},..,{}] then you can use the Array.sort method build into JavaScript, and just pass in a compare function that describes how to sort the objects by date.

For example:

Say you have an object like this:

var people = [
{
  "name": John,
  "birthday": new Date(1990, 8, 10);
},
{
  "name": Mark,
  "birthday": new Date(1991, 10, 17);
},
{
  "name": David,
  "birthday": new Date(1991, 7, 26);
}
];

Now to sort this array you can simply do the following:

people.sort(function(a,b) {
  return a.birthday - b.birthday;
});

Now the people array will be sorted by date.

For more information see this Mozilla Doc.

Vivek
  • 315
  • 2
  • 7
  • sorry for the question not being clear. actually am accessing A j son object and storing it in an array list. it consist of pick up date and passenger details. i want to sort and make an expandable list view consisting of date in the mainlist and passenger details in the sublist sorted according to the date . now cud you help ?? – Vaisakh Vinod Aug 11 '14 at 11:09
  • am on android platfrom – Vaisakh Vinod Aug 11 '14 at 11:22
  • If you are use a webview in the Android SDK, you should be able to just use JavaScript to do what you want, which would probably be better since you are using JSON objects. Either way I'll add another answer that might help. – Vivek Aug 12 '14 at 02:24
0

I am not too familiar with the Android SDK, but if you just need to sort an ArrayList that contains JSON objects by their date, I can help you with that part.

I would have your objects in the ArrayList parse your JSON using this tutorial, and then with the parsed date create a Date field in your object, and then have the object implement the Comparable interface as described in this tutorial. Then you can use Collections.sort(<list>) to sort the list.

Community
  • 1
  • 1
Vivek
  • 315
  • 2
  • 7