0

I want to click on delete button and after it to refresh my ListView and data in it, but nothing happens... ListView refreshes after I go back to MainActivity and start my new activity with it.

@Override
public void onClick(View v) {
    int position = (Integer) v.getTag();
    Object object = getItem(position);
    DataModel dataModel = (DataModel) object;

    switch (v.getId()) {
        case R.id.item_info:
            String selection = Base.BaseEntry.CONNECTION_NAME + " LIKE ?";
            String[] selectionArgs = { dataModel.getCONNECTION_NAME() };
            db.delete(Base.BaseEntry.TABLE_NAME, selection, selectionArgs);
            this.notifyDataSetChanged();
            Snackbar.make(v, "Connection: '" + dataModel.getCONNECTION_NAME() + "' has been deleted", Snackbar.LENGTH_LONG)
                    .setAction("No action", null).show();
            break;
    }
}

enter image description here

Little Fox
  • 1,212
  • 13
  • 39
  • Delete the element from the list that populates the listview and then call notifyDataSetChanged – Kapil G Aug 15 '17 at 11:27
  • By deleting the entry from datalist contains by ListAdapter, and after calling notifyDatasetChanged() method by this adapter's instance, you can achieve it. – Hassan Jamil Aug 15 '17 at 11:30

0 Answers0