title: android: Data refresh in listview after deleting from database
body: <p>I have an application which retrieves data from DB and displays it in a list view. I have a custom adapter for the same. So when I press the "delete" button, a delete button for each row in the list is displayed. If I press that, the particular row gets deleted in the DB and the same should be reflected in the listview also. The problem is, its not reflecting this change, I should close the app and reopen or move into some other activity and get back to see the updated results.</p>
  
  <p>So my question is: where do I call the <code>notifyDataSetChanged()</code> method to get it updated instantly?</p>
  
  <p>Here is my customadapter view:</p>
  
  <pre><code>public View getView(int position,  View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      MenuListItems menuListItems = menuList.get(position);
  
  
        if (convertView == null) {
             LayoutInflater inflater = (LayoutInflater) c
               .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             convertView = inflater.inflate(R.layout.customlist, parent, false);
  
            }
  
        Button ck = (Button) convertView.findViewById(R.id.delbox);
        if(i){
  
            ck.setVisibility(View.VISIBLE);}
            else{               
                ck.setVisibility(View.GONE);        
  
        }
  
  
          ck.setTag(menuListItems.getSlno());
          ck.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  final Integer Index = Integer.parseInt((String) v.getTag());
                  final DataHandler enter = new DataHandler(c);
                  DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          switch (which){
                          case DialogInterface.BUTTON_POSITIVE:
                              //Yes button clicked
                              enter.open();
                              enter.delet(Index);
                              enter.close();
                              notifyDataSetChanged();
                              dialog.dismiss();
  
                              break;
  
                          case DialogInterface.BUTTON_NEGATIVE:
                              //No button clicked
                              dialog.dismiss();
                              break;
                          }
                      }
                  };
  
                  AlertDialog.Builder builder = new AlertDialog.Builder(c);
                  builder.setMessage("Are you sure you want to Delete?").setPositiveButton("Yes", dialogClickListener)
                      .setNegativeButton("No", dialogClickListener).show();
  
              }
          });
  
  
              TextView id = (TextView) convertView.findViewById(R.id.tvhide);
              id.setText(menuListItems.getSlno());
  
            TextView title = (TextView) convertView.findViewById(R.id.tvtitle);
            title.setText(menuListItems.getTitle());
            TextView phone = (TextView) convertView.findViewById(R.id.tvpnumber);
            phone.setText(menuListItems.getPhone());
           // ck.setChecked(menuList.)
            notifyDataSetChanged();
            return convertView;
  }
  </code></pre>