title: Android notifyDataSetChanged from a custom adapter
body: <p>So my app uses a local SQLite db through a contentProvider
  In it's mainActivity I have a listView displaying the contents of a table from the above DB.</p>
  
  <p>I use a custom adapter to display the listview. Each item has a button in it's (custom) layout, that when pressed, shows a custom dialog that inserts a new record in that table, then the dialog gets dismissed.
  In order to achieve this behavior, I placed the button click handler inside the customAdapter.
  I would like to be able to refresh the listView after the inserting is done (so when dialog is dismissed)</p>
  
  <p>How can I achieve this?
  I should probably need to call notifyDataSetChanged somehow from inside the custom Adapter but I can't.</p>
  
  <p>In short, my custom adapter looks like this:</p>
  
  <pre><code>public class DisplayStuffAdapter extends BaseAdapter {
      private Context mContext;
      private ArrayList&lt;String&gt; id;
      private ArrayList&lt;String&gt; iduser;
      private ArrayList&lt;String&gt; product;
  
  
      public DisplayStuffAdapter(Context c){
          this.mContext = c;
      }
  
      public DisplayStuffAdapter(Context c,  ArrayList&lt;String&gt; id, ArrayList&lt;String&gt; userid, ArrayList&lt;String&gt; product) {
          this.mContext = c;
          this.id = id;
          this.userid = userid;
          this.product = product;
      }
  
   public int getCount() {
          return id.size();
      }
  
      public Object getItem(int position) {
          return null;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      public class Holder {
          TextView txt_id;
          TextView txt_userid;
          TextView txt_prod;
      }
  
  
    public View getView(int pos, View child, ViewGroup parent) {
          Holder mHolder;
          LayoutInflater layoutInflater;
          if (child == null) {
              layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              child = layoutInflater.inflate(R.layout.myitem, null);
              mHolder = new Holder();
              mHolder.txt_id = (TextView) child.findViewById(R.id.tv_MkId);
              mHolder.txt_userid = (TextView) child.findViewById(R.id.tv_MkUserId);
              mHolder.txt_prod = (TextView) child.findViewById(R.id.tv_MkProduct);
              child.setTag(mHolder);
          } else {
              mHolder = (Holder) child.getTag();
          }
          mHolder.txt_id.setText(id.get(pos));
          mHolder.txt_userid.setText(userid.get(pos));
          mHolder.txt_prod.setText(product.get(pos));
  
       Button bt = (Button) child.findViewById(R.id.itemButton);
          bt.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                LayoutInflater li = LayoutInflater.from(mContext);
                final View promptsView = li.inflate(R.layout.bid_dialog, null);
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
                alertDialogBuilder.setView(promptsView);
  alertDialogBuilder.setMessage("Input data")
                   .setIcon(R.drawable.add_red_24)
                   .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                      dialogInterface.dismiss();
                                  }
                              })
                   .setPositiveButton("Add new record", new DialogInterface.OnClickListener() {
                       @Override
                       public void onClick(DialogInterface dialogInterface, int i) {
                   ContentValues values = new ContentValues();
                   values.put(MyProvider.TCOL_ID, myid);
                   values.put(MyProvider.TCOL_OTHERID, Integer.toString(getActiveUserId()));
                   Uri uri = mContext.getContentResolver().insert(MyProvider.CONTENT_URI_TABLE, values);
                   values = new ContentValues();
                   dialogInterface.dismiss();
                        }
                      }
                    }
                 });
  
                  // create alert dialog
                  final AlertDialog alertDialog = alertDialogBuilder.create();
                  // show it
                  alertDialog.show();
                  alertDialog.setCanceledOnTouchOutside(false);
  ....
          }
      });
  ....
  </code></pre>
  
  <p>I remove some parts from the code to make it more readable.
  Now, in my MainActivity, I set the adapter like this:</p>
  
  <pre><code>public class MainActivity extends Activity{
      private ArrayList&lt;String&gt; id = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; userid = new ArrayList&lt;String&gt;();
      private ArrayList&lt;String&gt; product = new ArrayList&lt;String&gt;();
   ...
   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          fillListView();
      }
   ...
  
   private void fillListView(){
          id.clear();
          userid.clear();
          product.clear();
  
          String[] col = {MyProvider.TCOL_ID_ID, MyProvider.TCOL_USERID, MyProvider.TCOL_PROD};
          String where = "done = 1";
          Cursor mCursor =  MainActivity.this.getContentResolver().query(MyProvider.CONTENT_URI_TABLE, col, where, null, MyProvider.TCOL_DATE + " desc");
          if (mCursor != null) {
              if (mCursor.moveToFirst()) {
                  do {
                      id.add(Integer.toString(mCursor.getInt(0)));
                      userid.add(Integer.toString(mCursor.getInt(1)));
                      product.add(mCursor.getString(2));
                  } while (mCursor.moveToNext());
              }
          }
  
          DisplayStuffAdapter disadpt = new DisplayStuffAdapter(MainActivity.this,id,userid,product);
          disadpt.notifyDataSetChanged();
          ListView lv = (ListView) findViewById(R.id.mylistView);
          lv.setAdapter(disadpt);
      }
  </code></pre>
  
  <p>So this all works great, except that when I add a new record to the table using the customdialog described above... the dialog closes, and the listview remains unchanged.</p>
  
  <p>How can I refresh the listView?</p>