mardi 4 août 2015

After removing the item from the ListView, ListView is not updated

After removing the item from the lvSimple (ListView) I can not update the contents of LisView. The data from the database are removed. Items of ListView too. But i need to "flip through" fragments to see this. It's part of my code.

public class PageFragment extends Fragment {

public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == CM_DELETE_ID) {
        AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
        myDB.deleteRow(acmi.id);
        populateListView();
        return true;
    }
    return super.onContextItemSelected(item);
}

public void populateListView() {
    String[] fromFieldNames = new String[]{DBAdapter.KEY_DATE, DBAdapter.KEY_AREA, DBAdapter.KEY_PASSENGER};
    int[] toViewsID = new int[]{R.id.tvItemDate, R.id.tvItemArea, R.id.tvItemPassenger};
    SimpleCursorAdapter myC;
    myC = new SimpleCursorAdapter(view.getContext(), R.layout.item, c, fromFieldNames, toViewsID, 0);
    myC.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == 1) {
                String createDate = cursor.getString(columnIndex);
                textView = (TextView) view;
                textView.setText(dateFormat(createDate));
                return true;
            }
            return false;
        }
    });
    lvSimple.setAdapter(myC);
    myC.notifyDataSetChanged();
    lvSimple.invalidateViews();
}
}

Aucun commentaire:

Enregistrer un commentaire