zoukankan      html  css  js  c++  java
  • Handler基本用法

    片断一:
    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);

    片断二:
    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
    }
    片断三:
     public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case GET://get请求
                    tv_result.setText(msg.obj.toString());
                    break;
                case POST://post请求
                    tv_result.setText(msg.obj.toString());
                    break;
            }
        }

     
     new Thread(){
            @Override
            public void run() {
                super.run();
                try {
                String resutl = get("http://api.m.mtime.cn/PageSubArea/TrailerList.api");
                    Message msg = Message.obtain();
                    msg.what = GET;
                    msg.obj = resutl;
                    handler.sendMessage(msg);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
  • 相关阅读:
    vue-cli + webpack 构建vue.js开发环境
    JDK、Eclipse、Myeclipse、Tomcat等各种软件的版本详解(写给对版本和兼容性问题焦头烂额的你)
    总结下var、let 和 const 的区别
    vue双向绑定原理
    Vue中computed和watch的区别
    前端面试题总结
    微信开发之上传素材
    微信开发之向用户群发文本消息
    微信开发之获取用户详细列表
    TPshop入门大纲
  • 原文地址:https://www.cnblogs.com/dubo-/p/8432506.html
Copyright © 2011-2022 走看看