In my android Application, I added a recyclerview to show list of printing items. Each item view represents an information to print and also has a button to do printing. Print button color is light blue before printing and will change to yellow after printing . (printing code will execute here )
So, I clicked first print button and printed, button color was also changed to yellow . It is still okay to here. But, the problem is after scrolling to some distance, I found some buttons also changed color to yellow although it is not printed.
Here is my ViewHolder where I changed print button color in onClick() method.
public class IB17InventorySearchViewHolder extends BaseViewHolder<IB17InventorySearchResponse> {
@BindView(R.id.tv_location)
TextView tvLocation;
@BindView(R.id.tv_tuNo)
TextView tvTuNo;
@BindView(R.id.tv_sku)
TextView tvSku;
@BindView(R.id.tv_lot_no)
TextView tvLotNo;
@BindView(R.id.tv_qty)
TextView tvQty;
@BindView(R.id.btn_print)
Button btnPrint;
IB17InventorySearchResponse inventorySearchResponse;
private Activity mActivity;
public IB17InventorySearchViewHolder(View itemView, Activity mActivity) {
super(itemView);
this.mActivity = mActivity;
}
@Override
public void setData(IB17InventorySearchResponse data) {
this.inventorySearchResponse = data;
tvLocation.setText(data.getLoccode());
tvTuNo.setText(data.getTuno1());
tvSku.setText(data.getSkucode());
tvLotNo.setText(data.getLot4());
tvQty.setText(String.valueOf(data.getQty()));
btnPrint.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_print) {
if(BluetoothPrintHelper.printSucess)
btnPrint.setBackgroundColor(Color.parseColor("#fff111"));
} else {
// for whole itemview click
}
}
}`
Here is my Adapter
public class IB17InventorySearchRecyAdapter extends BaseRecyclerAdapter<BaseViewHolder, BaseModel> {
private List<IB17InventorySearchResponse> searchResponseList;
public Context context;
public IB17InventorySearchRecyAdapter(Context context, List<IB17InventorySearchResponse> searchResponseList) {
super(context);
this.context = context;
this.searchResponseList = searchResponseList;
}
@NonNull
@Override
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ib17_search_result_row, parent, false);
return new IB17InventorySearchViewHolder(view, (Activity) context);
}
@Override
public void onBindViewHolder(BaseViewHolder holder, final int position) {
holder.setData(searchResponseList.get(position));
}
@Override
public int getItemCount() {
return searchResponseList.size();
}}
My Question is how should I change child view(button) color of viewholder in recyclerview without impacting other itemview childs(viewholder buttons) Any ideas or alternative ways are appreciating!