How do I specify the sort order for children in an expandable list?

I am working on a conference application in which we want sessions to be grouped by time first and then by room location. I successfully sorted one by one or the other in my ExpandableListActivity, but failed with primary and secondary sorting.

conference application that displays the sessions first grouped by time and then by room location
(source: coreylatislaw.com )

Tune

  • Custom Content Provider (Extends ContentProvider)
  • Custom list adapter (extends BaseExpandableListAdapter)
  • Custom action list (extends ExpandableListActivity)

Inquiry

Cursor cursor = context.getContentResolver() .query(uri, ScheduleData.PROJECTION, null, null, ScheduleData.SORT_ORDER); 

The sort order

  public static final String SORT_ORDER = TimeSlots.QUALIFIED_TIMESTART + " ASC"; // timeslots.timestart 

Failed to Fulfill Primary & Secondary Sort Orders

  public static final String SORT_ORDER = TimeSlots.QUALIFIED_TIMESTART + " ASC, " + Locations.QUALIFIED_NAME + " ASC"; // timeslots.timestart ASC, locations.name ASC public static final String SORT_ORDER = TimeSlots.QUALIFIED_TIMESTART + ", " + Locations.QUALIFIED_NAME + " ASC"; // timeslots.timestart, locations.name ASC 

The second point does not seem to affect the order. Is this a limitation of ExpandableListActivity? Should I specify multiple sort order items in different ways?

+4
source share
3 answers

It turns out that there was a comparator in the class that redefined the sort order specified in the ORDERBY . When using the ORDERBY above, without a comparator, I got the required sort. You can do it anyway, but I kill the extra code and select the ORDERBY .

Comparator Path:

 // Sort children Collections.sort(group.children, CHILD_COMPARATOR); // Specify sort by location static final Comparator<Child> CHILD_COMPARATOR = new Comparator<Child>() { @Override public int compare (Child child1, Child child2) { return child1.location.toLowerCase().compareTo(child2.location.toLowerCase()); } }; 
+1
source

Just enter the data in the "ArrayAdapter", sort it the way you want, and then return the adapter to the list of actions.

0
source

This is actually not an answer, but I can not write comments. The string SORT_ORDER must be correct. But you can try using the shell and executing the sql lite query directly so that you can narrow down the problem.

  • run emulator with your application
  • in your console type:

    adb shell

  • Go to the directory of your application; eg:

    cd / data / data / com.myapp / databases)

  • run the SQLLite command line tool by typing:

    sqlite3 <filename>

  • If you do not know the name of your database file, simply enter "ls" to see all the files in this directory.

  • Now you can enter your request. For instance:

SELECT * FROM time intervals, locations ORDER BY timeslots.timestart, locations.name;

link: http://www.sqlite.org/sqlite.html

0
source

Source: https://habr.com/ru/post/1402302/


All Articles