Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于复用后导致错乱的问题 #3166

Open
roybill opened this issue May 8, 2020 · 2 comments
Open

关于复用后导致错乱的问题 #3166

roybill opened this issue May 8, 2020 · 2 comments

Comments

@roybill
Copy link

roybill commented May 8, 2020

竖向RecyclerView列表中,采用的多布局,其中有一种布局是横向滑动的RecyclerView,当这个横向滑动的RecyclerView滑动到最后一个item的时候,点击item中的关注按钮,点击后变为"已关注",现在我外层这个RecyclerView往下滑,然后再滑动回来这个横向的RecyclerView,这时候横向的这个RecyclerView全部都变为"未关注"了.这个横向的RecyclerView我已经设置了点击的标记.下面是横向RecyclerView的点击和adapter代码:
1.adapter代码:
`public class FocusHorizontalListAdapter extends BaseQuickAdapter<FocusBean.DataBean.ListBean, BaseViewHolder> {

public FocusHorizontalListAdapter(int layoutResId, @Nullable List<FocusBean.DataBean.ListBean> data) {
    super(layoutResId, data);
}

@Override
protected void convert(@NotNull BaseViewHolder helper, FocusBean.DataBean.ListBean listBean) {
    TextView focusText = helper.getView(R.id.tv_group_focus);
    boolean focused = listBean.isFocused();
    if(focused){
        focusText.setText("已关注");
        focusText.setTextColor(Color.parseColor("#999999"));
        focusText.setBackgroundResource(R.drawable.focused_shape);
    }else{
        focusText.setText("关注");
        focusText.setTextColor(Color.parseColor("#FFFFFF"));
        focusText.setBackgroundResource(R.drawable.unfocus_shape);
    }

}

}
2.该RecyclerView的item点击: RecyclerView recyclerView = helper.getView(R.id.rv_home_focus_horizontal_list);
List<FocusBean.DataBean.ListBean> data = new ArrayList<>();
for (int i = 0; i < 5; i++) {
FocusBean.DataBean.ListBean bean = new FocusBean.DataBean.ListBean();
data.add(bean);
}
LinearLayoutManager manager = new LinearLayoutManager(getContext());
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(manager);
FocusHorizontalListAdapter adapter = new FocusHorizontalListAdapter(R.layout.multiple_item_focus_horizontal, data);
recyclerView.setAdapter(adapter);

            adapter.addChildClickViewIds(R.id.tv_group_focus);
            adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                    Toast.makeText(getContext(), "点击了" + position, Toast.LENGTH_SHORT).show();
                    FocusBean.DataBean.ListBean listBean = data.get(position);
                    listBean.setFocused(true);
                    adapter.notifyItemChanged(position);
                }
            });`
@shuzhili
Copy link

我也有这个问题你怎么解决的啊

@roybill
Copy link
Author

roybill commented Aug 21, 2020

@shuzhili 只需要把UI和数据绑定就行了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants