• Handler发送消息及Timer添加不同的数据


    1.Timer timer;
    private Handler mHandler;
    private int quickId = 0;

    2.

    @Override
    protected void initData() {
        mHandler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        updateQuick();
                        break;
                }
            }
    
            ;
        };
    }
    

    3.

    private void childData() {
        if (quickId == 1) {
            childStatusBean = new ChildStatusBean();
            childStatusBean.setId(0);
            childStatusBean.setName("WI-FI");
            childStatusBean.setSuccess(true);
            childStatusBeans.add(childStatusBean);
        }
        if (quickId == 2) {
            childStatusBeanTwo = new ChildStatusBean();
            childStatusBeanTwo.setId(1);
            childStatusBeanTwo.setName("Cellular network");
            childStatusBeanTwo.setSuccess(true);
            childStatusBeans.add(childStatusBeanTwo);
        }
        if (quickId == 3) {
            childStatusBeanThree = new ChildStatusBean();
            childStatusBeanThree.setId(2);
            childStatusBeanThree.setName("Bluetooth");
            childStatusBeanThree.setSuccess(false);
            childStatusBeans.add(childStatusBeanThree);
        }
        if (quickId == 4) {
            childStatusBeanFour = new ChildStatusBean();
            childStatusBeanFour.setId(3);
            childStatusBeanFour.setName("GPS");
            childStatusBeanFour.setSuccess(false);
            childStatusBeans.add(childStatusBeanFour);
        }
        if (quickId == 5) {
            childStatusBeanFive = new ChildStatusBean();
            childStatusBeanFive.setId(4);
            childStatusBeanFive.setName("Battery");
            childStatusBeanFive.setSuccess(true);
            childStatusBeans.add(childStatusBeanFive);
        }
    
        binding.recyclerViewStatus.setLayoutManager(new LinearLayoutManager(getContext()));
        //设置分割线
        binding.recyclerViewStatus.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
        childStatusAdapter = new ChildStatusAdapter(childStatusBeans);
        binding.recyclerViewStatus.setAdapter(childStatusAdapter);
    }

    4.

    private class MyTask extends TimerTask {
        @Override
        public void run() {
            Message message = new Message();
            message.what = 1;
            mHandler.sendMessage(message);
    
        }
    }

    5.

    private class MyTask extends TimerTask {
        @Override
        public void run() {
            Message message = new Message();
            message.what = 1;
            mHandler.sendMessage(message);
    
        }
    }

    6.

    quickTestDialog.buttonYesSetOnclick(view1 -> {
        childStatusBeans = new ArrayList<>();
        timer = new Timer();
        timer.scheduleAtFixedRate(new MyTask(), 1, 1000);
        quickTestDialog.close();
    });

  • 相关阅读:
    docker简介
    #P05804. 伪素数
    JAVA前端开发介绍
    数据库迭代模型扩展
    【AGC】.p12证书文件如何获取MD5
    63. 不同路径 II
    283 移动零
    JSP Webshell 免杀
    Python HTTP Server
    真offer收割机 第二弹~大厂如何考察候选人?(附答案详解)
  • 原文地址:https://blog.csdn.net/xige1995/article/details/126977774