Reputation: 908
i am working on an app to develop my knowledge so far i have created a calendar app which user can make appointment when clicking on a date. i then have a delete button which opens all the appointments created in a fresh activity, there i have: a list view which displays all appointments a textview which displays the selected appointment (selected by the user to delete) and a button remove. the remove button removes all the items from the sqlite but i can only see this working when the application is restarted i know i am missing something else in my code.. how do i clear the listview at the same time any help would be much appreciated
my code:
delete all method
public void deleteAll() {
db.delete(TABLE_NAME, null, null);
}
button code:
public void onClick(View v) {
switch(v.getId()){
case R.id.removeBtn:
dm.deleteAll();
break;
}
thank you }
Upvotes: 2
Views: 1811
Reputation: 9585
If you are actually changing the data from the Adapter used in the ListView, you could use requery() method on the cursor used to populate the Adapter. This should reflect your changes!
Upvotes: 1
Reputation: 699
Maybe not the most elegant, but I don't build my UI in onCreate(). Instead, in onCreate(), I call another method initializeUI(), and that is where I build my user interface. Then, anytime I do something that should be reflected in the interface (update the database or whatever), I just need to call my method initializeUI() again.
Edit: Also look into notifyDataSetChanged() for your adapter as exampled here
Upvotes: 3
Reputation: 209
First check if your database is writable (getWritableDatabase)
Then check that your "TABLE_NAME" is in fact the table name.
Then you could try to use execSQL("delete from " + TABLE_NAME);
if that does not work, you could try to close the db.
finally try putting it in a transaction beginTransaction(); .. delete.. endTransaction();
Upvotes: 1