title: android: refresh listview on clicking a button in a list item
body: <p>i have a listview that retrieves rows from a database which are marked as favorites, i.e,  which have boolean value 1 in the column 'favorite'. it has a textview and a button. upon clicking the button, that particular item is removed from favorites, i.e, that row in the database is updated and its favorite value is set to boolean 0. this much is working perfectly. but i want the listview to be refreshed after this so that the particular item disappears from the listview. i tried using <code>notifyDataSetChanged();</code> but its not working. how do i do it? the relevant portions of the code are pasted below:</p>
  
  <p>Activity class:</p>
  
  <pre><code>public class ListActivity extends Activity{
      public Cursor c;
      public int lcid;
      private ListView lView;
      private ArrayList&lt;ListItemNew&gt; newList;
      private ListNewAdapter mAdapterNew;
  
  @Override
  public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      Context context = getApplicationContext();
      setContentView(R.layout.favs);
      getActionBar().setDisplayHomeAsUpEnabled(true);
  
      final DataBaseHelper db = new DataBaseHelper(context);
      try {db.createDataBase();} catch (IOException e) {e.printStackTrace();}
      db.openDataBase();  
  
      newList = new ArrayList&lt;ListItemNew&gt;();
  
      c=db.getFavs();
      prepareList();
      db.close();
  
      lView = (ListView) findViewById(R.id.listView1);
  
      mAdapterNew = new ListNewAdapter(getApplicationContext(), newList);
      lView.setAdapter(mAdapterNew); 
      lView.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView&lt;?&gt; myAdapter, View myView, int position, long mylng) {
          mAdapterNew.notifyDataSetChanged();
          lView.setAdapter(mAdapterNew);
          final Intent k = new Intent(ListActivity.this, MainActivity.class);
      k.putExtra("id", x);
          finish();
          startActivity(k);
        }
      });
  
  
  
  }
  
  public void prepareList()
  {
        c.moveToFirst();
        do{
            newList.add(new ListItemNew(c.getString(0), c.getString(1)));
        }while (c.moveToNext()); 
  
  }
  
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.main, menu);
  
      return true;
  }
  
  
  
  }
  </code></pre>
  
  <p>Adapter class:</p>
  
  <pre><code>public class ListNewAdapter extends BaseAdapter {
       public View getView(int position, View convertView, ViewGroup parent) {
          if (convertView == null) {
              LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
              convertView = mInflater.inflate(R.layout.list_item_new, null);
          }
  
          TextView txtTitle = (TextView) convertView.findViewById(R.id.list_new_title);
          txtTitle.setText(newListItems.get(position).getTitle());
          Button imgBtn = (Button) convertView.findViewById(R.id.delete_btn);
          //.......declarations etc
  
          imgBtn.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) 
              {
                  AlertDialog.Builder alertbox = new AlertDialog.Builder(v.getRootView().getContext());
                  alertbox.setMessage("Are you sure you wanna remove this item from your favorites?");
                  alertbox.setTitle("Warning");
                  alertbox.setIcon(R.drawable.trn_03);
  
                  alertbox.setPositiveButton("Yes",
                          new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface arg0, int arg1) {
  
                                  final DataBaseHelper db = new DataBaseHelper(context);
                                  try {db.createDataBase();} catch (IOException e) {e.printStackTrace();}
                                  db.openDataBase(); 
                                  final int newid = Integer.valueOf(id);
                                  db.UpdateRemoveFav(newid); 
                                  db.close();
                                  notifyDataSetChanged();
                              }
                          });
                  alertbox.setNegativeButton("No", null);
                  alertbox.show();
  
              }
          });
  
          return convertView;
      }
  }
  </code></pre>