title: Custom ListView update, delete not reflecting in Android?
body: <p>I am using custom adapter for displaying list view with text view and image view.</p>
  
  <p><img src="https://i.stack.imgur.com/LdnZs.png" alt="enter image description here"></p>
  
  <p>This is my output screen. Now I want to delete a item from listview and I achieve that by using the below codes</p>
  
  <pre><code> holder.img_delete.setTag(tempValues.getCompanyName());
      holder.img_delete.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View view) {
              eventDB.open();
              eventDB.DeleteByText(view.getTag().toString());
              eventDB.close();
              Toast.makeText(ctx, "Deleted", 10).show();
              notifyDataSetChanged();
  
  
          }
      });
  </code></pre>
  
  <p>Now the problem is the listView not updating the items after deletion was performed. Please give me suggestions. </p>
  
  <p><strong>@Dante</strong>   </p>
  
  <pre><code>public class CustomAdapter extends BaseAdapter   implements OnClickListener {
  
  private ArrayList data;
  private static LayoutInflater inflater=null;
  public Resources res;
  ListModel tempValues=null;
  int i=0;
  Context ctx;
  EventCate_DBAdapter eventDB;
  
  public CustomAdapter(Context c, ArrayList d,Resources resLocal) {
  
  
  
      data=d;
      res = resLocal;
      ctx=c;
  
      inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      eventDB = new EventCate_DBAdapter(ctx);
  }
  
  
  public int getCount() {
  
      if(data.size()&lt;=0)
          return 1;
      return data.size();
  }
  
  public Object getItem(int position) {
      return position;
  }
  
  public long getItemId(int position) {
      return position;
  }
  
  
  public static class ViewHolder{
  
      public TextView text;
  
      public static ImageView img_edit,img_delete;
  
  }
  
  
  public View getView(int position, View convertView, ViewGroup parent) {
  
      View vi=convertView;
      ViewHolder holder;
  
      if(convertView==null){ 
  
  
          vi = inflater.inflate(R.layout.tabitem, null); 
  
  
          holder=new ViewHolder();
          holder.text=(TextView)vi.findViewById(R.id.tv_event_cat);
          holder.img_edit=(ImageView)vi.findViewById(R.id.iv_edit);
          holder.img_delete=(ImageView)vi.findViewById(R.id.iv_delete);
  
          vi.setTag(holder);
      }
      else  
          holder=(ViewHolder)vi.getTag();
  
      if(data.size()&lt;=0)
      {
          holder.text.setText("No Data");
  
      }
      else
      {
  
          tempValues=null;
          tempValues = (ListModel) data.get(position);
  
  
           holder.text.setText(tempValues.getCompanyName());
  
  
  
           vi.setOnClickListener(new OnItemClickListener(position));
  
  
  
      }
  
      holder.img_edit.setTag(tempValues.getCompanyName());
      holder.img_edit.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View view) {
              Toast.makeText(ctx, "Edit = "+view.getTag().toString(), Toast.LENGTH_SHORT).show();
  
          }
      });
      holder.img_delete.setTag(tempValues.getCompanyName());
      holder.img_delete.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View view) {
              eventDB.open();
              eventDB.DeleteByText(view.getTag().toString());
              eventDB.close();
              Toast.makeText(ctx, "Deleted", 10).show();
              notifyDataSetChanged();
              notifyDataSetInvalidated();
  
  
          }
      });
  
      return vi;
  }
  
  @Override
  public void onClick(View v) {
          Log.v("CustomAdapter", "=====Row button clicked");
  }
  
  
  private class OnItemClickListener  implements OnClickListener{           
      private int mPosition;
  
      OnItemClickListener(int position){
           mPosition = position;
      }
  
      @Override
      public void onClick(View arg0) {
         SettingsActivity sct = (SettingsActivity)ctx;
          sct.onItemClick(mPosition);
      }               
  }  
  
  }
  </code></pre>
  
  <p>Delete items works fine. I need an another solution for updating list items.</p>
  
  <p>This is my coding </p>
  
  <pre><code>eventDB.open();
  
              eventDB.update(Id.get(0), etEventCategory.getText().toString());
  
              eventDB.close();
              data.set(pos,etEventCategory.getText().toString());
              dialog.dismiss();
  
              notifyDataSetChanged();
              notifyDataSetInvalidated();
  </code></pre>