Android CursorLoader with selection and selectionArgs[] -
i using loader
recyclerview.adapter
list items. want list specific items database table. did:
public loader<cursor> oncreateloader(int id, bundle args) { string selectionargs1[]={"1","13","14"}; string selection1 = databaseopenhelper.column_id + " in ("; (int = 0; < selectionargs1.length; i++) { selection1 += "?, "; } selection1 = selection1.substring(0, selection1.length() - 2) + ")"; string[] projection1 =... return new cursorloader(getactivity(),studentcontentprovider.content_uri1, projection1, selection1,selectionargs1, null); }
normally give null,null
selection
, selectionargs
here, list items specific ids
. problem arises when new item added table , want list it. cursor
returning not aware of new item since gave 3 specific items, detects when there change on 3 items.
how list when there new item added id
, want list ? should project items database recyclerview.adapter
, filter ids
in onbindviewholder()
?
since have restricted ids
in cursor
, changed if specific items change, not when new item added. did trick on onloadfinished()
create new cursor
, swap new cursor. when there change, new cursor selection
, selectionargs
again:
public void onloadfinished(loader<cursor> loader, cursor data) { switch (loader.getid()) { case loader_id:{ string selectionargs1[]={...}; string selection1 = databaseopenhelper.column_id + " in ("; (int = 0; < selectionargs1.length; i++) { selection1 += "?, "; } selection1 = selection1.substring(0, selection1.length() - 2) + ")"; string[] projection1 =... mdataset1 = getactivity().getcontentresolver().query(studentcontentprovider.content_uri1, projection1, selection1, selectionargs1, null); madapter.swapcursor(mdataset1); break; } }
Comments
Post a Comment