我重新发布问题,因为没有人可以建议我正确的方法来解决此问题,因此请不要这样做,请在加载类并设置我设置的recyclerView适配器时以正确的方式建议我有些情况不是根据我的情况改变了我的数据。这是我的代码在bindViewHolder方法中
@Override
public void onBindViewHolder(final CarTypesHolder holder, int position) {
myAppRoomDataBase=Room.databaseBuilder(activity,MyAppRoomDataBase.class,dbname).allowMainThreadQueries().build();
list=myAppRoomDataBase.userDao().getAll();
if(list.size()!=0){
II= Integer.parseInt(list.get(0).RideId);
}
if (II==1)
{
holder.llRoot.setBackgroundColor(Color.parseColor("#999999"));
holder.mCarType.setTextColor(Color.parseColor("#ffffff"));
}
else
{
holder.llRoot.setBackgroundColor(Color.parseColor("#f3f3f3"));
holder.mCarType.setTextColor(Color.parseColor("#2196F3"));
}
holder.setOnItemClickListner(new setOnitemclick() {
@Override
public void ImageClick(View v,int position1) {
I=position1;
notifyDataSetChanged();
try {
if (list.size() != 0) {
myAppRoomDataBase.userDao().delete();
list.clear();
}
VehicleClick vehicleClick = new VehicleClick();
vehicleClick.setRideId(String.valueOf(position1));
myAppRoomDataBase.userDao().insert(vehicleClick);
list.add(vehicleClick);
}
catch (Exception e)
{
}
}
});
if (I==position)
{
holder.llRoot.setBackgroundColor(Color.parseColor("#999999"));
holder.mCarType.setTextColor(Color.parseColor("#ffffff"));
}
else
{
holder.llRoot.setBackgroundColor(Color.parseColor("#f3f3f3"));
holder.mCarType.setTextColor(Color.parseColor("#2196F3"));
}
Picasso.with(mContext).load(carTypesModel.getImagePath()).into(holder.mCarTypeImage);
}