RecyclerView onBindViewHolder无法绘制我的视图

时间:2018-09-26 00:43:44

标签: java android android-recyclerview

单击我的项目时,我正在排序,但是排序后,收藏夹图标的填充色未设置或消失,这就是我正在做的事情

@Override
    public void onBindViewHolder(@NonNull final LineViewHolder holder, final int position) {

        final Line line = lines.get(position);
 holder.line_name.setText(line.getName());
     holder.favorite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if (!Utils.userLogged()) {
                        showLoginInviteDialog();
                    } else {


                        if (!line.isFavorite()) {

                            holder.favoriteFilled.setVisibility(View.VISIBLE);
                            line.setIsfavorite(true);
                            //order
                            Collections.sort(lines, new LineComparator());
                            notifyDataSetChanged();


                        } else {
                            holder.favoriteFilled.setVisibility(View.GONE);
                            line.setIsfavorite(false);
                            Collections.sort(lines, new LineComparator());
                            notifyDataSetChanged();

                        }

                    }


                }
            });
}

这就是问题enter image description here

1 个答案:

答案 0 :(得分:2)

holder.line_name.setText(line.getName());之后添加以下行

if (line.getIsFavorite()){
    holder.favoriteFilled.setVisibility(View.VISIBLE);
}else{
    holder.favoriteFilled.setVisibility(View.GONE);

}