Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got the same problem before, I don't think in this case <code>notifyDataSetChanged</code> alone can help you. What has changed is actually your cursor, so you need to reload it using the function <a href="http://developer.android.com/reference/android/widget/CursorAdapter.html#changeCursor%28android.database.Cursor%29" rel="noreferrer">changeCursor</a> on your custom adapter. Here is an example:</p> <pre><code>changeCursor(yourCursor); notifyDataSetChanged(); </code></pre> <p>Here is the full code of how I managed this in my Fragment class:</p> <pre><code>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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload