9

My problem is quite simple, but my code is not working. I want to sort result of a ParseQuery into the ParseQueryAdapter before display it into a ListView.

products.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<Product>() {

        @Override
        public void onLoaded(List<Product> data, Exception e) {
            Collections.sort(data, LastDealComparator);
            products.notifyDataSetInvalidated();
        }

        @Override
        public void onLoading() {
        }

    });

I checked in debugger data is sorted by the Comparator ... but not updated into the ParseQueryAdapter ... notifyDataSetInvalidated do nothing.

For information, initially my problem is to sort a query on a pointer field :

query.orderByDescending("deal.date");

But that's not working too ... so i write a manual sort.

MLKiiwy
  • 133
  • 1
  • 8
  • Got the same problem – jean d'arme Aug 18 '15 at 14:17
  • Dont know if there is a feature like this in the framework you are are working with but on swift you could do something like "query.orderByDescending("deal.date");" usign "whereKey:matchesQuery:". – adolfosrs Sep 14 '15 at 19:19

1 Answers1

0

You can create the onLoaded event and create the sort index (sort of HashMap)

@Override
public void onLoaded(List<ParseObject> objects, Exception e)

And in the getItem function you can map the data based on the index.

Example of a reverse order list:

@Override
public ParseObject getItem(int position) { //For descending order
    return super.getItem(getCount() - position - 1);
}
xnagyg
  • 4,784
  • 2
  • 32
  • 24