My book "Hello Android" gives this as a way to use the db user helper, adjust the cursor, and then configure the adapter as follows:
Cursor cursor CustomDatabaseHelper test = new CustomDatabaseHelper(this); try { cursor = getData(); showData(cursor); } finally { test.close(); }
With this, however, every time I need to update a dataset, I need to continue to work with this block of code (which is a bit difficult inside onClick () for the button due to the lack of "this".
Is this the best way to update the dataset, or should I look at removing .close and issuing the adapter .notifyDataSetChanged ()? If I do this, sometimes I get power like (and I canβt remember at the moment), but sometimes it canβt delete correctly. I think it could be because the database is currently open and it is trying to open again.
Should we also declare variables for cursors, DatabaseHelpers and Adapter in the class (outside OnCreate) so that they are accessible for all functions?
I understand that this is just bad programming at this point, but I'm trying to get some guidance on the best way to do something.
android refresh listview
Simon Nov 16 2018-10-16 12:31
source share