Recyclerview 为什么不能局部刷新

发布于 2022-09-04 01:25:35 字数 2936 浏览 20 评论 0

1 CameraViewHolder中有一些回调,用来更新状态
但是好像没有生效 回调函数也执行了,但是状态没有更新
代码如下


class CameraViewHolder extends RecyclerView.ViewHolder implements Item {

@BindView(R.id.title_ll)
LinearLayout cameraHeadGroup;
@BindView(R.id.camera_title_tv)
TextView cameraTitleTv;
@BindView(R.id.camera_empty_iv)
ImageView cameraEmptyIv;
@BindView(R.id.camera_live)
TextureVideoView playView;
@BindView(R.id.camera_label_iv)
ImageView cameraLabelIv;
@BindView(R.id.camera_status_iv)
ImageView cameraStatusIv;
@BindView(R.id.live_progress)
ProgressBar mProgressBar;
@BindView(R.id.btn_refresh)
ImageButton btnRefresh;

private Device realDevice;

private int videoState = START_IDLE;



private static final int START_IDLE = 0;
private static final int START_ACTIVED = 1;
private static final int START_DEACTIVED = 2;


private CameraListAdapter mCameraListAdapter;

CameraViewHolder(View view,CameraListAdapter cameraListAdapter){
     super(view);
     mCameraListAdapter = cameraListAdapter;
     ButterKnife.bind(this,view);

}

public void onBind(final int position , Device item){

    realDevice = item;
    cameraTitleTv.setText(item.getTitle());
    btnRefresh.setVisibility(View.GONE);
    mProgressBar.setVisibility(View.VISIBLE);
    TextureVideoView.PlayerCallback callback = new TextureVideoView.PlayerCallback() {
        @Override
        public void cameraPlayFailed(View view, String error) {
            mProgressBar.setVisibility(View.GONE);
            btnRefresh.setVisibility(View.VISIBLE);
            KLog.d("播放失败");

            cameraEmptyIv.setVisibility(View.GONE);
            mCameraListAdapter.notifyItemChanged(position,null);

        }

        @Override
        public void cameraPlayGotData(View view) {
            KLog.d("播放成功");
            mProgressBar.setVisibility(View.GONE);
            btnRefresh.setVisibility(View.GONE);
            cameraStatusIv.setBackgroundResource(R.drawable.mon_green);
            cameraEmptyIv.setVisibility(View.GONE);
            mCameraListAdapter.notifyItemChanged(position,null);


        }

        @Override
        public void cameraStop() {
            cameraEmptyIv.setVisibility(View.VISIBLE);
            cameraStatusIv.setBackgroundResource(R.drawable.mon_red);
            mCameraListAdapter.notifyItemChanged(position,null);
        }
    };

    playView.setPlayerCallback(callback);
    playView.setRealDevice(item);



}

private void reset(){          


}

@OnClick(R.id.btn_refresh)
void refresh(){
    mProgressBar.setVisibility(View.VISIBLE);
    btnRefresh.setVisibility(View.GONE);
    playView.start();
}


@Override
public void setActive(View newActiveView, int newActiveViewPosition) {
    videoState = START_ACTIVED;          
    KLog.d("active:" + newActiveViewPosition);
}

@Override
public void deactivate(View currentView, int position) {
    KLog.d("deactivate :" + position);
    videoState = START_DEACTIVED;
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半﹌身腐败 2022-09-11 01:25:35

每次刷新都会执行你的 onBind() 方法,

public void onBind(final int position , Device item){
    // 这三个 View 又给 set 了 一次,把你刷新前设置的状态覆盖掉了
    cameraTitleTv.setText(item.getTitle());
    btnRefresh.setVisibility(View.GONE);
    mProgressBar.setVisibility(View.VISIBLE);
     ....
}
   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文