I'm currently working on RecyclerView implementation on my project. When I set item on RecyclerView and scroll, I lost its position.
I Use Some if and else condition to click and change the color of text but its change when I'll not scroll the RecyclerView item.
Please suggest me the right way how to handle this condition.
adapter.setOnItemClickListner(new LoadVehicleTypeAdapter.setOnitemclick() {
@Override
public void ImageClick(int position, String Name,String Description,int id) {
LinearLayout linearLayout = null;
CustomTextView customTextView = null;
try {
for (int i = 0; i < messages.size(); i++) {
linearLayout = (LinearLayout) rvVehicleTypes.getChildAt(i).findViewById(R.id.root1);
customTextView = (CustomTextView) rvVehicleTypes.getChildAt(i).findViewById(R.id.frag_cartypes_inflated_name);
if (i==position) {
linearLayout.setBackgroundColor(Color.parseColor("#999999"));
customTextView.setTextColor(Color.parseColor("#FFFFFF"));
} else {
linearLayout.setBackgroundColor(Color.parseColor("#f3f3f3"));
customTextView.setTextColor(Color.parseColor("#2196F3"));
}
}
//Toast.makeText(getActivity(),Name, Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
}
}
});