4

Using latest Parse library v1.5.1

Thanks to the update now I can do:

ParseQueryAdapter<ParseObject> mAdapter = new ParseQueryAdapter<ParseObject>(MainActivity.this, new ParseQueryAdapter.QueryFactory<ParseObject>() {
    @Override
    public ParseQuery<ParseObject> create() {

        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseObject.class);
        query.fromLocalDatastore();

        return query;
    }
});
mListView.setAdapter(mAdapter);

Now I have some pinned objects and they appear correctly, but when I unpin them like so:

//Some ParseObject in the above adapter
object.unpinInBackground(new DeleteCallback() {
    @Override
    public void done(ParseException e) {
        if(e == null) {
            //I beleive this would be the correct approach.
            mAdapter.notifyDataSetChanged();
        }
    }
});

Naturally I want that item to disappear from the corresponding ListView, but it doesn't. But say I go back to a different activity and revisit this activity, the ListView is displayed properly without the recently unpinned object.

Is this a bug? If not what am I doing wrong?

janakagamini
  • 237
  • 3
  • 11

2 Answers2

2

I have the same problem) I solve it with invoke method ParseQueryAdapter.loadObjects().

PavelGP
  • 1,681
  • 1
  • 13
  • 11
0

You can try mAdapter.remove(object) before calling notifyDataSetChanged();

unpinInBackground removes the object from the database. Probably the adapter has a local copy of the object.

Looks like there is no remove method in ParseQueryAdapter.

Here is an response from official source:

Since a ParseQueryAdapter is designed to always show the results of a ParseQuery, you would need to use an API request to reload the query.

https://www.parse.com/questions/delete-a-object-using-parsequeryadapter

LordRaydenMK
  • 13,074
  • 5
  • 50
  • 56
  • 2
    Okay got it, I have to use `loadObjects()` to rerun the query. – janakagamini Jun 05 '14 at 08:17
  • Then you might want to accept my answer, or write your own and accept it (to mark the question as answered). :) – LordRaydenMK Jun 05 '14 at 08:29
  • I'm not convinced it's 100% correct though, say if I was looking at an item on page two, and unpinned it, when I call loadObjects(), the listView would display from the top again, resulting in a weird user experience. – janakagamini Jun 05 '14 at 12:39