我使用的是列表视图,有一个名为列表项“订单”按钮。 我想显示“嘀”的形象当用户按下按钮,当用户再次按下按钮将其隐藏。
我的问题是,当我点击的第一个项目按钮,选中第4,8项的图像也出现了。
这是onClickListener的调节器,
viewHolderItem.btnOrder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSelected = shoe.isSelected();
if(isSelected){
viewHolderItem.ivTick.setImageDrawable(null);
isSelected = false;
}else{
viewHolderItem.ivTick.setImageDrawable(mContext.getResources().getDrawable(R.drawable.tick));
isSelected = true;
}
shoeList.get(position).setSelected(isSelected);
obj.getAdapter().notifyDataSetChanged();
}
});
什么是这个问题的原因是什么?
更新:这是我的adapte getview方法
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolderItem viewHolderItem;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.component_order_shoe_row,null);
viewHolderItem = new ViewHolderItem();
viewHolderItem.tvName = (TextView)convertView.findViewById(R.id.tv_component_order_shoe_name);
viewHolderItem.tvPrice = (TextView)convertView.findViewById(R.id.tv_component_order_shoe_price);
viewHolderItem.tvDesc = (TextView)convertView.findViewById(R.id.tv_component_order_shoe_description);
viewHolderItem.ivPic = (ImageView)convertView.findViewById(R.id.iv_component_order_shoe_pic);
viewHolderItem.ivTick = (ImageView)convertView.findViewById(R.id.iv_component_order_shoe_tick);
viewHolderItem.spinnerSize = (Spinner)convertView.findViewById(R.id.spinner_component_order_shoe_size);
viewHolderItem.etQty = (EditText)convertView.findViewById(R.id.et_component_order_shoe_qty);
viewHolderItem.btnOrder = (Button)convertView.findViewById(R.id.btn_component_order_shoe_order);
convertView.setTag(viewHolderItem);
}else{
viewHolderItem = (ViewHolderItem)convertView.getTag();
}
final Shoe shoe = shoeList.get(position);
viewHolderItem.tvName.setText(shoe.getShoeName());
String text = String.valueOf(shoe.getPrice());
int integerPlaces = text.indexOf('.');
int decimalPlaces = text.length() - integerPlaces - 1;
if(decimalPlaces==1){
viewHolderItem.tvPrice.setText("Rs."+ text + "0");
}else{
viewHolderItem.tvPrice.setText("Rs."+ text);
}
viewHolderItem.tvDesc.setText(shoe.getDesc());
Bitmap bmp = AppControl.convertStringToBitmap(shoe.getImg());
viewHolderItem.ivPic.setImageBitmap(bmp);
int smallest = shoe.getSmallestSize();
int largest = shoe.getLargestSize();
Integer[] arr = getSizeArray(smallest,largest);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(mContext, android.R.layout.simple_spinner_dropdown_item,arr);
viewHolderItem.spinnerSize.setAdapter(adapter);
viewHolderItem.btnOrder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isSelected = shoe.isSelected();
if(isSelected){
viewHolderItem.ivTick.setImageDrawable(null);
isSelected = false;
}else{
viewHolderItem.ivTick.setImageDrawable(mContext.getResources().getDrawable(R.drawable.tick));
isSelected = true;
}
shoeList.get(position).setSelected(isSelected);
obj.getAdapter().notifyDataSetChanged();
}
});
return convertView;
}