-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recyvlerview头部设置此控件 一直被复用导致时间停止或错乱 #91
Comments
+1,怎么解决的 |
@liguangze 我目前只能把时间器提出来到recyclerview外面去了,不被复用 |
@Munccccc 怎么提取到外面,时间控件是在holder中获取的,时间值是服务器返回的,在什么时候设置,会报空的啊 |
@liguangze 布局里面把时间器写到recyclerview的外面 不要到holer头部里面 |
@Munccccc 不在recyclerview里面,那只会显示一个倒计时啊,我的需求是每个item都有倒计时 |
CountdownView中的onDetachedFromWindow方法中调用了stop方法,注释这个stop方法,就能用了,在头视图中 |
在Adapter重写onViewAttachedToWindow()方法并且调用start(),然后在onDetachedFromWindow()方法中调用stop()方法就不会出现停止的现象了。onViewAttachedToWindow()方法是当适配器创建的view(即列表项view)被窗口分离(即滑动离开了当前窗口界面)就会被调用,onDetachedFromWindow是 当列表项出现到可视界面的时候调用。 |
@xcatx9527 意思是继承CountdownView,然后重写onDetachedFromWindow方法,注释掉吗 |
countView.addOnAttachStateChangeListener 在这个控件添加监听 然后在onViewAttachedToWindow()方法里面 再次调用start方法就OK了 改源码太麻烦了 |
countView.addOnAttachStateChangeListener 添加监听 然后在onViewAttachedToWindow()方法里面 再次调用start方法就OK了 改源码太麻烦了 |
countView.addOnAttachStateChangeListener 添加监听 然后在onViewAttachedToWindow()方法里面 再次调用start方法就OK了 改源码太麻烦了 |
countView.addOnAttachStateChangeListener 添加监听 然后在onViewAttachedToWindow()方法里面 再次调用start方法就OK了 改源码太麻烦了 |
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import java.util.Timer;
import java.util.TimerTask;
import cn.iwgang.countdownview.CountdownView;
/**
* 新增计时器线程,用作实时记录倒计时的时间戳,修复原Countdown在<code>{@link #onDetachedFromWindow()}</code>方法中调用了{@code stop()}方法,
* 但并没有在<code>{@link #onAttachedToWindow()}</code>方法中恢复计时的问题,并且,计时器也没有实时的记录运行中的准确数值。
* <p/>
* booooo 2018/11/23 11:49
*/
public class ZkCountdownView extends CountdownView
{
public ZkCountdownView(Context context)
{
super(context);
}
public ZkCountdownView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public ZkCountdownView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
private long time = 0;
private boolean isStartingTask = false;
private final Timer mTimer = new Timer();
private final TimerTask task = new TimerTask()
{
@Override
public void run()
{
time -= 1000;
}
};
@Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
Log.d(ZkCountdownView.class.getSimpleName(), "onAttachedToWindow");
this.start(time);
}
@Override
public void start(long millisecond)
{
super.start(millisecond);
time = millisecond;
if (!isStartingTask)
{
Log.d(ZkCountdownView.class.getSimpleName(), "start timer time=" + time);
mTimer.scheduleAtFixedRate(task, 0, 1000);
isStartingTask = true;
}
}
@Override
public void updateShow(long ms)
{
super.updateShow(ms);
time = ms;
}
public void finishTimer()
{
mTimer.cancel();
Log.d(ZkCountdownView.class.getSimpleName(), "stop timer");
}
} |
No description provided.
The text was updated successfully, but these errors were encountered: