当点击操作栏上的按钮时,我希望某个布局在我的所有recyclerview项目上都可见。
谷歌没有帮助,我也不知道如何解决这个问题。这方面的一个例子是,当用户想要从收件箱中删除大量SMS消息时,按住该按钮会突然启用Recyclerview中每个项目的复选框。
编辑:
public class ViewCartAdapter extends RecyclerView.Adapter<ViewCartAdapter.DataViewHolder>
{
private List<ViewCartModel.Product> dataList;
private Context con;
public ViewCartAdapter(Context context, List<ViewCartModel.Product> list)
{
this.dataList = list;
con = context;
}
@Override
public int getItemCount()
{
return dataList.size();
}
@Override
public void onBindViewHolder(final DataViewHolder dataViewHolder, int i)
{
dataViewHolder.setClickListener(new DataViewHolder.ClickListener()
{
@Override
public void onClick(View v, int pos, boolean isLongClick)
{
}
});
ViewCartModel.Product item = dataList.get(i);
Picasso.with(con).load(item.getThumb().replaceAll(" ", "%20")).into(dataViewHolder.itemImage);
dataViewHolder.itemName.setText(Html.fromHtml(item.getName().toUpperCase()).toString());
dataViewHolder.itemPrice.setText(item.getPrice());
dataViewHolder.categoryID = item.getKey();
}
@Override
public DataViewHolder onCreateViewHolder(ViewGroup viewGroup, int i)
{
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tile_cart, viewGroup, false);
DataViewHolder dvh = new DataViewHolder(itemView);
return dvh;
}
public static class DataViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
{
protected ImageView itemImage;
protected TextView itemName;
protected TextView itemPrice;
protected String categoryID;
private ClickListener clickListener;
public DataViewHolder(View v)
{
super(v);
itemImage = (ImageView) v.findViewById(R.id.itemImage);
itemPrice = (TextView) v.findViewById(R.id.itemPrice);
itemName = (TextView) v.findViewById(R.id.itemName);
v.setOnClickListener(this);
}
public interface ClickListener
{
/**
* Called when the view is clicked.
*
* @param v view that is clicked
* @param position of the clicked item
* @param isLongClick true if long click, false otherwise
*/
public void onClick(View v, int position, boolean isLongClick);
}
public void setClickListener(ClickListener clickListener)
{
this.clickListener = clickListener;
}
@Override
public void onClick(View v)
{
clickListener.onClick(v, getPosition(), false); // here, get position
}
}
}
答案 0 :(得分:0)
当绑定到ViewHolder时,你应该保持一个布尔值来告诉我是否显示或隐藏了复选框。然后,当您长按按钮时,切换布尔值,并在适配器上调用“notifyItemRangeChanged”以重新绑定ViewHolder。