java - Android : Issue deleting last item from RecyclerView -
i using recyclerview
in following manner show list of places items updated in sqlite db .
the items deleted fine , updated swipe them . when swipe delete last item , comes in view . when close app , reopen app , item deleted though .
but when item swiped delete , in instance of app running , item not deleted view after swiping multiple times .
@override public void onswiped(recyclerview.viewholder viewholder, int swipedir) { int swipedposition = viewholder.getadapterposition(); placelistadapter adapter = (placelistadapter) mrecyclerview.getadapter(); int pos = viewholder.getadapterposition(); // build appropriate uri string row id appended string stringid = places.get(pos).getid(); log.d("testhro", stringid); uri uri = placecontract.placeentry.content_uri; uri = uri.buildupon().appendpath(stringid).build(); log.d("testhhd", uri.tostring()); // completed (2) delete single row of data using contentresolver getcontentresolver().delete(uri, null, null); madapter.notifydatasetchanged(); refreshplacesdata(); }
refreshplacesdata()
private void refreshplacesdata() { uri uri = placecontract.placeentry.content_uri; cursor data = getcontentresolver().query( uri, null, null, null, null); if (data == null || data.getcount() == 0) return; log.d("countis", string.valueof(data.getcount())); list<string> guids = new arraylist<string>(); while (data.movetonext()) { guids.add(data.getstring(data.getcolumnindex(placecontract.placeentry.column_place_id))); } pendingresult<placebuffer> placeresult = places.geodataapi.getplacebyid(mclient, guids.toarray(new string[guids.size()])); placeresult.setresultcallback(new resultcallback<placebuffer>() { @override public void onresult(@nonnull placebuffer places) { madapter.swapplaces(places); mainactivity.this.places = places; mgeofencing.updategeofenceslist(places); if (misenabled) mgeofencing.registerallgeofences(); } }); }
am missing something? thanks.
edit : tried updating adapter instead of madapter , still no change
edit 2
public void swapplaces(placebuffer newplaces) { mplaces = newplaces; if (mplaces != null) { // force recyclerview refresh this.notifydatasetchanged(); } }
note : verified loggers :
d/countiszero: true (inside refreshplacesdata())
you should refresh view
after changing dataset.
mainactivity.this.places = places; // data set changed placelistadapter adapter = (placelistadapter) mrecyclerview.getadapter(); adapter.notifydatasetchanged();
or should change order of
madapter.notifydatasetchanged(); // notify later refreshplacesdata(); // refresh first
firstly change dataset , notify adapter.
Comments
Post a Comment