In Recycle view how to Highlight always one adapter item with the click and without click

前端 未结 4 1692
刺人心
刺人心 2021-01-29 14:24

Here I clicked on the item to change item background and color. I\'ve stored the clicked item value in the database and change the layout color and text color and recreating the

4条回答
  •  清酒与你
    2021-01-29 14:49

    for keep track record you need to add Boolean variable in TaxiTypeResponse.Message boolean isClick=false; and toggle this in

    holder.setOnItemClickListner(new setOnitemclick() {
    
        @Override
        public void ImageClick(View v, int position) {
               CarTypesModelsList.get(position).isClick=!CarTypesModelsList.get(position).isClick;
               notifyDataSetChanged();
       }
    }
    

    and modify below code as follow

     if (CarTypesModelsList.get(position).isClick) {
    
            holder.llRoot.setBackgroundColor(Color.parseColor("#999999"));
            holder.mCarType.setTextColor(Color.parseColor("#ffffff"));
            Animation bounce = AnimationUtils.loadAnimation(mContext, R.anim.bounce);
            holder.llRoot.startAnimation(bounce);
    
     } 
     else{
            holder.llRoot.setBackgroundColor(Color.parseColor("#f3f3f3"));
            holder.mCarType.setTextColor(Color.parseColor("#2196F3"));
     }
    

提交回复
热议问题