android - Update listview inside ListFragment from Cursor Adapter -
in android have custom adapter, in custom adapter create view text , button delete text. of works fine , can delete record database have been unable refresh list.
the list looks little this:
------------------------------------ text text text text | delete button| ------------------------------------ text text text text | delete button| ------------------------------------
my first instinct use this:
qclistfragment frag = (qclistfragment) getsupportfragmentmanager().findfragmentbyid(r.id.listfragment);
at point call method inside list fragment re-query list... cant because adapter not extend fragment. i'm finding hard let fragment know data has been changed.
anyhow, last thought rebuild activity thought that not best thing , there had better way... i'm sure simple i'm missing last question was!
(i can post more code if helpful) update: here entire adapter class
public class calccursoradapter extends simplecursoradapter implements filterable{
private context mcontext; private listview mlistview; private int mlayout; private cursor mcursor; protected static class viewholder { protected textview text; protected imagebutton button; private int position; } @suppresswarnings("deprecation") public calccursoradapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); this.mcontext = context; this.mlayout = layout; this.mcursor = c; //mlistview = .getlistview(); } @override public void bindview(view view, context context, cursor cursor) { textview summary = (textview)view.findviewbyid(r.id.calctvprice); textview savings = (textview)view.findviewbyid(r.id.calctvsavings); summary.settext(cursor.getstring(cursor.getcolumnindexorthrow("qcfinalprice"))); savings.settext(cursor.getstring(cursor.getcolumnindexorthrow("qcsavings"))); } @override public view newview(context context, cursor cursor, viewgroup parent) { viewholder holder = new viewholder(); layoutinflater inflater = layoutinflater.from(context); view v = inflater.inflate(r.layout.calc_list_item, parent, false); holder.button = (imagebutton) v.findviewbyid(r.id.qcbtndelete); holder.button.setonclicklistener(deletebutton); holder.position = cursor.getint(cursor.getcolumnindexorthrow("_id")); bindview(v, context, cursor); v.settag(holder); return v; } private onclicklistener deletebutton = new onclicklistener() { public void onclick(view v){ view view = (view) v.getparent(); viewholder holder = (viewholder) view.gettag(); int position = holder.position; dbhelper mdbhelper; mdbhelper = new dbhelper(mcontext); mdbhelper.open(); mdbhelper.deletecalc(position); mdbhelper.close(); string test = integer.tostring(position); toast.maketext(mcontext.getapplicationcontext(), test, toast.length_short).show(); notifydatasetchanged(); } }; public long qcitemid(int position) { return position; }
}
any appreciated!
thanks.
i think misunderstood concept of adapter , fragment. can set adapter fragment or adapterview in fragment. after requery data, call adapter.notifydatasetchanged(), fragment or adapterview refreshed.
Comments
Post a Comment