我很想改变Recyclerview
所选项目的背景(只有一个):
爪哇:
public class HorizontalViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView img;
private SparseBooleanArray selectedItem = new SparseBooleanArray();
public HorizontalViewHolder(View itemView) {
super(itemView);
img = (ImageView) itemView.findViewById(R.id.img);
itemView.setOnClickListener(this);
}
void onBindView(int position) {
final String s = spacecrafts.get(position);
Glide.with(c).asBitmap().load(s).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(img);
}
@Override
public void onClick(View view) {
monRecyclerViewClickListener.onClick(view, spacecrafts.get(getAdapterPosition()));
if (selectedItem.get(getAdapterPosition(), false)) {
selectedItem.clear();
view.setSelected(false);
} else {
selectedItem.put(getAdapterPosition(), true);
view.setSelected(true);
}
// img.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.imagebordertwo));
}
}
问题: 当我选择另一个项目时,前一个项目保持选中状态
萧十郎
相关分类