• 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();
    }
  • 相关阅读:
    企业应用架构研究系列三:应用系统集成
    企业应用架构研究系列十九:Docker开发环境
    企业应用架构研究系列二十:创建&发布Docker
    前端NEXT实践系列:(一)ECMAScript 6.0技术栈
    企业应用架构研究系列二十七:Vue3.0 之环境的搭建与Vue Antd Admin探索
    企业应用架构研究系列五:极限编程(XP)& 敏捷管理(Scrum)
    记一次HIV初筛假阳性的经历
    C#发送邮件
    Ubuntu允许root登录
    lerna学习
  • 原文地址:https://www.cnblogs.com/dubo-/p/8432506.html
Copyright © 2020-2023  润新知