listview 的复用问题

在不考虑局部刷新的情况下:::::::

每次listview在适配器里填充完数据后,当改变其中一个item的数据,
并上下滑动的时候会因为listview的复用问题导致这个或者其他的item的数据又变了回来,
这个可以用个hashmap来解决

首先在适配器里添加个hashmap

    private Context context;
    private ArrayList vp_list;
    private HashMap hm = new HashMap();
 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
//        if(hm.get(position) == null){
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.member_card_item_item, null);
            holder.tv_member_card_plant_name = (TextView)
                    convertView.findViewById(R.id.tv_member_card_plant_name);
            holder.tv_member_card_price = (TextView)
                    convertView.findViewById(R.id.tv_member_card_price);
            holder.et_member_card_del = (EditText) convertView.findViewById(R.id.et_member_card_del);
            holder.tv_member_card_residue = (TextView)
                    convertView.findViewById(R.id.tv_member_card_residue);
//            convertView.setTag(holder);
//            hm.put(position, convertView);
            convertView.setTag(holder);
        } else {
//            convertView = hm.get(position);
            holder = (ViewHolder) convertView.getTag();
        }
        final MemberPackageInfo info = vp_list.get(position);
        hm.put(position, info);///////
        holder.tv_member_card_plant_name.setText(hm.get(position).product_name);
        holder.tv_member_card_price.setText(hm.get(position).price + "元");
        holder.tv_member_card_residue.setText("剩余" + hm.get(position).product_num);

你可能感兴趣的:(Android,listview,hashmap)