Android development, how to solve the data confusion after RecyclerView reuse?


this is a RecyclerView, that slides from left to right. When I click on the first item follower, it becomes "followed", but when I slide to the right, some of the item data also change to "followed", and the data is still messed up when I slide back.

this is how I handle it, but I can"t:

 public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        //TODO:bug,.item
        TextView tvNotFocus = view.findViewById(R.id.tv_related_theme_recommended_focus);//
        String focus = tvNotFocus.getText().toString();
        List<TopicRelatedRecommendedBean> data = getData();
        TopicRelatedRecommendedBean topicRelatedRecommendedBean = data.get(position);
        boolean select = topicRelatedRecommendedBean.isSelect();
        Log.d(TAG, "1145=   "+select);
        if (view.getId() == R.id.tv_related_theme_recommended_focus) {
            if (focus.equals("")) {
                tvNotFocus.setText("");
                tvNotFocus.setBackgroundResource(R.drawable.topic_already_focus_shape);
            } else if (focus.equals("")) {
                tvNotFocus.setText("");
                tvNotFocus.setBackgroundResource(R.drawable.release_button_shape);
            }
        }
//        if (select) {
//            Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
//            topicRelatedRecommendedBean.setSelect(false);
//            tvNotFocus.setText("");
//            tvNotFocus.setBackgroundResource(R.drawable.release_button_shape);
//        } else {
//            Toast.makeText(mContext, "", Toast.LENGTH_SHORT).show();
//            topicRelatedRecommendedBean.setSelect(true);
//            tvNotFocus.setText("");
//            tvNotFocus.setBackgroundResource(R.drawable.topic_already_focus_shape);
//        }
    }
Mar.02,2021

add a field to your bean that you want to follow or not, change the value of the field when you click, determine whether you care or not when the data is populated, and then set a different state. Here is the virtual code

    //
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        //TODO:bug,.item
        TextView tvNotFocus = view.findViewById(R.id.tv_related_theme_recommended_focus);//
        String focus = tvNotFocus.getText().toString();
        List<TopicRelatedRecommendedBean> data = getData();
        TopicRelatedRecommendedBean topicRelatedRecommendedBean = data.get(position);
        boolean select = topicRelatedRecommendedBean.isSelect();
        Log.d(TAG, "1145=   "+select);
        if (view.getId() == R.id.tv_related_theme_recommended_focus) {
            topicRelatedRecommendedBean.isAttention = !topicRelatedRecommendedBean.isAttention;
            notifyDataSetChanged();
        }
    }
    
    //
    @Override
    public void onBindViewHolder(RecyclerHolder holder, int position) {
        List<TopicRelatedRecommendedBean> data = getData();
        TopicRelatedRecommendedBean topicRelatedRecommendedBean = data.get(position);
     
        holder.tvNotFocus.setText(topicRelatedRecommendedBean.isAttention ? "" : "");
        holder.tvNotFocus.setBackgroundResource(topicRelatedRecommendedBean.isAttention ? R.drawable.topic_already_focus_shape : R.drawable.release_button_shape);
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cbfd-2c330.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cbfd-2c330.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?