Search code examples
javaandroidandroid-listview

Listview item remove method is not working


Problem - when I click on confirm button item do not disappear from the list and after touch on the listview again item is removed from the list. Why this happening please give me solution. Overall remove method is not working in real time.

final ArrayList<orderTrialHelper> list_data;
Context context;
int resource;
ProgressDialog pd;


public orderTrial(Context context, int resource, ArrayList<orderTrialHelper> list_data) {
    super(context, resource, list_data);
    this.list_data = list_data;
    this.context = context;
    this.resource = resource;

}


@Override
public View getView(final int position, View convertView, final ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.cust_list_trials, null, true);
    }
    final orderTrialHelper listdata = getItem(position);



    id_no.setText(String.valueOf(listdata.getId_no()));
    date.setText(listdata.getDate());
    quantity.setText(String.valueOf(listdata.getQuantity()));
    confirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


                            list_data.remove(position);
                            notifyDataSetChanged();
            }

    });
    return convertView;
}

Solution

  • Try using recyclerview. May be that can solve your problem.