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();
    }
  • 相关阅读:
    DButils工具类能够用来获取数据库连接向数据库插入更新删除对象
    Android 实现ActionBar定制
    查看CentOs6.5/7的系统版本号
    安装Was liberty之步骤
    在centOS上安装VNC
    SCP远程拷贝命令
    Was liberty资料总结
    罗杰斯:做你喜欢的工作,你会变成个有钱人
    【Java/csv】一个CSV文件解析类(转载)
    当你的才华还撑不起你的野心时,那你就应该静下心来学习。
  • 原文地址:https://www.cnblogs.com/dubo-/p/8432506.html
Copyright © 2011-2022 走看看