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(); });