NotifyDataSetChanged en el adaptador Curser no funciona con listfragment

Tengo un listfragment que exhibe una lista de una base de datos. Tengo todo funcionando correctamente a excepción de un pequeño artículo que no puedo seeem para aclarar. La vista de lista se ve así.

----------------------------------------------------- text text text | some more text | delete row button | ----------------------------------------------------- 

Mi problema: cuando un usuario presiona el botón de fila de eliminación, la fila se elimina de la base de datos pero no se eliminará de la pantalla hasta que la actividad se detenga y se inicie de nuevo.

Sé que notifyDataSetChanged() es el método preferido para actualizar estas listas, pero no parece hacer nada … De todas formas, a continuación está mi código para el adaptador de cursor donde se llama notifyDataSetChanged() .

 public class CalcCursorAdapter extends SimpleCursorAdapter{ private Context mContext; private ListView mListView; private int mLayout; private Cursor mcursor; protected static class ViewHolder { protected TextView text; protected ImageButton button; private int position; } @SuppressWarnings("deprecation") public CalcCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); this.mContext = context; this.mLayout = layout; this.mcursor = c; //mListView = .getListView(); } @Override public void bindView(View view, Context context, Cursor cursor) { TextView summary = (TextView)view.findViewById(R.id.calctvPrice); TextView savings = (TextView)view.findViewById(R.id.calctvSavings); TextView percentOff = (TextView)view.findViewById(R.id.calctvpercentOff); summary.setText(cursor.getString(cursor.getColumnIndexOrThrow("qcFinalPrice"))); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { ViewHolder holder = new ViewHolder(); LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.calc_list_item, parent, false); holder.button = (ImageButton) v.findViewById(R.id.qcbtnDelete); holder.button.setOnClickListener(deleteButton); holder.position = cursor.getInt(cursor.getColumnIndexOrThrow("_id")); bindView(v, context, cursor); v.setTag(holder); return v; } private OnClickListener deleteButton = new OnClickListener() { @SuppressWarnings("deprecation") public void onClick(View v){ View view = (View) v.getParent(); ViewHolder holder = (ViewHolder) view.getTag(); int position = holder.position; DbHelper mDbHelper; mDbHelper = new DbHelper(mContext); mDbHelper.open(); mDbHelper.deleteCalc(position); mDbHelper.close(); String test = Integer.toString(position); Toast.makeText(mContext.getApplicationContext(), test, Toast.LENGTH_SHORT).show(); notifyDataSetChanged(); //ListView list = getListView(); } }; public long qcItemId(int position) { return position; } } 

Gracias por tu ayuda.

ACTUALIZAR:

Nuevo botón Código dentro de mi adaptador:

 private OnClickListener deleteButton = new OnClickListener() { @SuppressWarnings("deprecation") public void onClick(View v){ v.invalidate(); View view = (View) v.getParent(); view.invalidate(); ViewHolder holder = (ViewHolder) view.getTag(); int position = holder.position; DbHelper mDbHelper; mDbHelper = new DbHelper(mContext); mDbHelper.open(); mDbHelper.deleteCalc(position); mDbHelper.close(); String test = Integer.toString(position); Toast.makeText(mContext.getApplicationContext(), test, Toast.LENGTH_SHORT).show(); Cursor newCursor = getCursor(); changeCursor(newCursor); notifyDataSetChanged(); //ListView list = getListView(); } }; 

Tengo el mismo problema antes, no creo que en este caso notifyDataSetChanged solo puede ayudarle. Lo que ha cambiado es en realidad su cursor, por lo que necesita volver a cargarlo con la función changeCursor en su adaptador personalizado. Aquí hay un ejemplo:

 changeCursor(yourCursor); notifyDataSetChanged(); 

Aquí está el código completo de cómo logré esto en mi clase Fragment:

 ImageButton newCat = (ImageButton)categoriesListTitle.findViewById(R.id.new_category); newCat.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { categoriesDialog.dismiss(); AlertDialog.Builder newCatAlert = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogStyle)); newCatAlert.setTitle("New category"); // Set an EditText view to get user input final EditText newCatET = new EditText(v.getContext()); newCatAlert.setView(newCatET); newCatAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String newCatName = newCatET.getText().toString(); db.addCategory(newCatName); mAdapter.changeCursor(db.getAllCategoriesByRate(currentRate));//Here I update the cursor used in my adapter //In your case (you do not use a dialog), you have to add this line I think: //mAdapter.notifyDataSetChanged(); categoriesDialog.show(); } }); newCatAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); newCatAlert.show(); } }); categoriesLV.setAdapter(mAdapter); 
  • Android Pull-to-Refresh con Fragmento ListView y Adaptador ListView personalizado
  • Onclicklistner no funciona en el listview de fragmentos
  • Cómo puede el estilo el ListView de un ListFragment
  • ¿Qué diferencia hay entre getSupportFragmentManager () y getChildFragmentManager ()?
  • Android: ListFragment: Cómo actualizar la lista
  • ListFragment da ListView cuyo atributo id es 'android.R.id.list'
  • Cómo actualizar el ListView en lista de arrastre de ListView?
  • Android actualiza una lista de fragmentos de su actividad principal
  • Añadir un encabezado a fragmentlist android
  • implementa OnScrollListener dentro de listFragment
  • Configuración del color de fondo de los elementos ListView en el botón
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.