Почему при нажатии на элемент RecyclerView срабатывает несколько OnClick методов, т.е. меняется бэкграунд у нескольких элементов?
Разметка:
<android.support.v7.widget.RecyclerView
android:id="@+id/calculator_activity_what_to_exchange_horizontal_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white" />
Класс:
mFromRecyclerView = (RecyclerView) findViewById(R.id.calculator_activity__horizontal_recycler_view);
mFromAdapter = new CalculatorHorizontalAdapter();
mFromRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
mFromRecyclerView.setAdapter(mFromAdapter);
mFromAdapter.setCourseArray(courseArray);
mFromAdapter.notifyDataSetChanged();
Адаптер:
public class CalculatorHorizontalAdapter extends RecyclerView.Adapter<CalculatorHorizontalAdapter.MyViewHolder> {
private Course[] courseArray;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView ShortTv;
public TextView LongTv;
public TextView Long2Tv;
public LinearLayout holderLayout;
public MyViewHolder(View view) {
super(view);
ShortTv = (TextView) view.findViewById(R.id.item_calculator_currency_short_tv);
holderLayout = (LinearLayout) view.findViewById(R.id.item_calculator_currency_ll);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_calculator_currency, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
if (courseArray[position].currencyBuy != null)
holder.ShortTv.setText(setOfCourses.get(position));
holder.holderLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
holder.holderLayout.setBackgroundColor(Color.parseColor("#0f67c0"));
}
});
}
@Override
public int getItemCount() {
return courseArray.length;
}
public CalculatorHorizontalAdapter(Course[] courseArray) {
this.courseArray = courseArray;
}
public CalculatorHorizontalAdapter() {
}
public void setCourseArray(Course[] courseArray) {
this.courseArray = courseArray;
}
}