在我的recyclerView
适配器中,我实现了简单的 CountDownTimer 15 秒,在这个实现中 countDownTimer 工作正常,在列表中recylcerview
我在布局视图中有一些 countDownTimer 并且我想在具有 countDownTimer 的当前行再次启动时启动和停止这个 countDownTimer 并且当 countDownTimer 不是可见或未显示在列表中,必须停止。喜欢 Instagram 播放和停止视频
简化适配器:
public class InstagramFeedsAdapter extends RecyclerView.Adapter<InstagramFeedsAdapter.InstagramFeedsViewHolder> {
...
@Override
public void onBindViewHolder(final InstagramFeedsViewHolder holder, int position) {
holder.bind(position);
}
public class InstagramFeedsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
...
private boolean expanded;
private CountDownTimer timer;
public InstagramFeedsViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
ButterKnife.bind(this, itemView);
}
@Override
public void onClick(View v) {
}
public void bind(int position) {
if (timer != null) {
timer.cancel();
}
timer = new CountDownTimer(15000, 1000) {
@SuppressLint("DefaultLocale")
@Override
public void onTick(long leftTimeInMilliseconds) {
pager_count_down_timer.setVisibility(View.VISIBLE);
long seconds = leftTimeInMilliseconds / 1000;
pager_count_down_timer.setText(String.format("%02d", seconds % 60));
}
@Override
public void onFinish() {
pager_count_down_timer.setVisibility(View.GONE);
timer = null;
}
}.start();
}
}
现在我如何在可见性项目上启动和停止这个 countDownTimer?