如何解决Android中Holder的循环视图滚动问题?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (51)

以下是我使用的代码

private class SeekBarUpdaterRight implements Runnable {
        @Override
        public void run() {
            if (null != rightMusicPlayerHolder) {
                if (player != null) {
                    int curVolume = player.getCurrentPosition();
                   rightMusicPlayerHolder.seekMusicRight.setProgress(curVolume);
                    // int currentHour = curVolume / HOUR;
                    int currentMint = (curVolume % HOUR) / MINUTE;
                    int currentSec = (curVolume % MINUTE) / SECOND;
                    rightMusicPlayerHolder.txtDurationStartRight.setText(String.format("%02d:%02d", currentMint, currentSec));
                    rightMusicPlayerHolder.seekMusicRight.postDelayed(this, 100);
                    Log.print("==========rightMusicPlayerHolder=========" + rightMusicPlayerHolder.getAdapterPosition());
                }
            }
        }
    }
提问于
用户回答回答于

试试下面的例子:

ViewHolder clickedViewHolder;

private void setClickedViewHolder(ViewHolder clickedViewHolder) {
    this.clickedViewHolder = clickedViewHolder;
}

private ViewHolder getClickedViewHolder() {
    return clickedViewHolder;
}

@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
    holder.rowView.setTag(holder);
    holder.rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentViewHolder((MyAdapter.ViewHolder) v.getTag());
        }
    });

    ViewHolder currClickedViewHolder = getClickedViewHolder();  // this is the last viewHolder clicked on.
}

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励