简体   繁体   中英

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;
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM