0

My app mostly works. The only problem is that when I want to delete a single item, the confirmation dialogue pops up as required and once the "yes" button is selected the app still does not delete the item.

It is getting the correct burger name. The burger's name was "hshz", quantity is 4 and price is 6. The log message was:

12-29 05:13:04.963 27316-27316/com.example.omar.burgerinventory D/TEST: Burger name is: hshz
                                                                        Quantity: 4
                                                                        Price: $6

The entry data is completely deleted once I hit "yes" on the confirmation dialogue. When I click the entry again, the app crashes. So this means that the data is wiped out but the list item still appears on the list for some reason. So I guess the problem here is that I'm able to delete the data but not clear it from the list.

  • 2
    Delete a single item from WHERE? Which should be the result? in the UI, in the database or what? Which code are you using for accomplish your task? Which is the stacktrace when the crash occurs? Take a look [here](http://stackoverflow.com/help/how-to-ask) – GVillani82 Dec 29 '16 at 12:31
  • Refetch your data from database after delete the entry and notify your list with data. – SANAT Dec 29 '16 at 12:58

3 Answers3

0

Your problem is because you are making changes to your database correctly, assuming you are using database, but you are not updating your list adapter telling it that it's underlying data has changed..which has reference to the same old data before deleting the item..you need to fetch the new list from database after the code where you are deleting the item.. Please take a look at this accepted answer.. Android ListView not refreshing after notifyDataSetChanged . Also it will help if you post the code for your adapter and where you are deleting the item.

Community
  • 1
  • 1
saurabh169
  • 499
  • 1
  • 4
  • 12
-1

After deleting data, remove data from particular position from list by using:-

try{
    al_data.remove(particular_position); 
   }catch(Exception e){}
notifyDataSetChanged();
priyanka kataria
  • 417
  • 5
  • 17
-1

You can take good example from this tutorial: http://belencruz.com/2015/04/refresh-data-in-a-custom-android-adapter/

Ziad Ahmad
  • 95
  • 13