Listview项目删除方法不起作用

问题描述 投票:0回答:1

问题-当我单击确认按钮项目时,该项目不会从列表中消失,并且在触摸列表视图后,再次将项目从列表中删除。为什么会这样,请给我解决方案。整体删除方法无法实时运行。

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;
}
java android android-listview
1个回答
0
投票

尝试使用recyclerview。也许可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.