Remove ListView item

1

Well I have a list, which has some items that the user creates. With this I'm also wanting to give an option to the user to remove the items so as not to accumulate, so I researched and found a way to use onItemLongClickListener to remove the item. Here is the code:

  adapter.remove(adapter.getItem(position));
  adapter.notifyDataSetChanged();

Well so far so good when I gave LongClick he removed the item, however after I went into another activity of the app and came back to that activity of ListView the item I removed appeared again, What do I do to fix this, to go to the other activity back and the item still removed?

Note, I'm using SQLiteDatabase.

Thank you!

    
asked by anonymous 11.01.2015 / 23:46

1 answer

2

You performed the first step, which was to delete the ListView item. However, this item will persist as it has not been deleted from the database. When the Activity is recreated, the list is rearranged, since the query of that "deleted" item finds the item in the Bank.

I recommend that you review your code and enter something like this to complete the last missing step to solve your problem:

 //---delete um valor em particular ---
public boolean deleteValor(String nome) 
{
    return db.delete(DATABASE_TABLE, KEY_NAME + "=" + nome, null) > 0;
}
    
12.01.2015 / 01:48