How to increment a value on view holder variables in android?

前端 未结 3 1697
深忆病人
深忆病人 2021-01-22 18:18

I have a viewholder in my Android app and I tried to set an incremented value on a textfield. I tried it like following,

Activity



        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 18:59

    You also need to set a tag for the Button, if you want to manipulate the holder item.

       if (convertView == null) {
            ...
            holder.buttonPlus = (ButtonRectangle) convertView.findViewById(R.id.buttonPlus);
            holder.buttonPlus.setTag(holder);
            holder.buttonPlus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Holder current= (Holder) v.getTag();
                    current.inc=current.inc+1;
                    notifyDataSetChanged();
                }
            });
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
    

提交回复
热议问题