小编Iga*_*nov的帖子

notifyDataSetChanged() 在 recyclerview 上做什么?为什么每次我调用 notifyDataSetChanged() 时它都会不断添加新数据?

我正在尝试在我的 recyclerview 方法上实现此方法更改recyclerview中所选项目的背景颜色

我正确地遵循了脚本,它以我想要的方式工作。是的,它会改变颜色,但每次我单击该项目时,它似乎都在不断添加新数据。我正在使用 2 recyclerview。

我在第一个 recyclerview 上的方法调用了另一个方法来再次绘制一个 recyclerview。就像当我们调用第一个 recyclerview 时,它也调用了第二个 recyclerview。

这是我的脚本:

    @Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.viewItem.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,true);
    holder.viewItem.setLayoutManager(layoutManager);

    HoriSpacingDecoration horiSpacingDecoration = new HoriSpacingDecoration(Utils.convertDpToPixel(10,context));
    holder.viewItem.addItemDecoration(horiSpacingDecoration);

    adapterChart = new ChartItemAdapter(context);
    holder.viewItem.setAdapter(adapterChart);

    mItemsChart.clear();

        holder.textView.setText(mBulan.get(position));
        int dataTertinggi = Integer.parseInt(Collections.max(mItems));
        int botol = dataTertinggi/5;
        int ci = niceround(dataTertinggi);
        Log.d(TAG, "onBindViewHolder: pembulatan " + ci);
            ukuran = Integer.parseInt(mItems.get(position))/botol;

            if(Integer.parseInt(mItems.get(position))%10 < botol)
            {
                ukuran2=1;
                ukuran+=ukuran2;
            }
            else
            {
                ukuran2=1;
                ukuran+=ukuran2;
            } …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

2
推荐指数
1
解决办法
2003
查看次数

标签 统计

android ×1

android-recyclerview ×1