Handler基本用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Handler基本用法相关的知识,希望对你有一定的参考价值。

1.
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
currentPosition++;
Log.d("recyclerBanner", currentPosition + " ");
mOverFlyingLayoutManager.scrollToPosition(currentPosition);
// recyclerView.smoothScrollToPosition(currentPosition);
mHandler.postDelayed(this, 3000);
}
};
mHandler.postDelayed(mRunnable, 3000);

2.项目中实践用法
mainHandler.sendEmptyMessageDelayed(Url.Banner,3000);
@Override
protected void disposeMainHandlerCallMethod(Message msg) {
super.disposeMainHandlerCallMethod(msg);
switch(msg.what){
case Url.Banner:
currentPosition++;
Log.d("recyclerBanner", currentPosition + " ");
mOverFlyingLayoutManager.scrollToPosition(currentPosition);
// recyclerView.smoothScrollToPosition(currentPosition);
mainHandler.sendEmptyMessageDelayed(Url.Banner,3000);
break;
default:break;
}//end of switch
}
 

以上是关于Handler基本用法的主要内容,如果未能解决你的问题,请参考以下文章