I have a recyclerview to show tables at restaurant, if a table has an active order then I'm setting the background color to Amber. Moreover, if I click on any table, it's background should become grey (I'm using setSelected for this) It works fine for some items but for some, the recyler item's background becomes Amber even though it doesn't have an ActiveOrder. It happens for the tables near a table which actually has an active order. I'm not sure why this is happening.
OnBindViewMethod:
public void onBindViewHolder(TableItemViewHolder holder, int position) {
Table table = mTableList.get(position);
holder.mTableNameTextView.setText(table.getTableName());
holder.tableItemLayout.setSelected(selectedPosition==position);
if(table.getOrderID()!=0 && selectedPosition!=position)
{
Log.i("OrderId",table.getTableName()+table.getOrderID());
holder.tableItemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.colorAmber));
}
holder.tableItemLayout.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyItemChanged(selectedPosition);
selectedPosition = position;
notifyItemChanged(selectedPosition);
}
}
);
}