美文网首页
2019-04-12 service中修改Fragment的ui

2019-04-12 service中修改Fragment的ui

作者: YuQiao0303 | 来源:发表于2019-04-12 13:22 被阅读0次

    service 中:

       //更新ui : handler & messa
            Message msg = new Message();
            msg.what = Constant.UPDATE_TEMPERATURE_HUMIDITY;
            msg.obj = HexUtil.encodeHexStr(data);  //String类型
            HomeFragment.handler.sendMessage(msg);
    

    Fragment 中:

    public static Handler handler;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
    
            View view = inflater.inflate(R.layout.fragment_home, container, false);
            Button rdmindTest = view.findViewById(R.id.send_notice);
            final TextView lastTime = view.findViewById(R.id.last_time);
            //更新ui的handler
            handler = new Handler(){
                @Override
                public void handleMessage(Message msg){
                    if(msg.what == Constant.UPDATE_TEMPERATURE_HUMIDITY)
                    {
                        lastTime.setText( (String) msg.obj);
                        //lastTime.append("更新ui:"+ i +"\r\n");
                    }
                }
            };
    ...
    

    相关文章

      网友评论

          本文标题:2019-04-12 service中修改Fragment的ui

          本文链接:https://www.haomeiwen.com/subject/swlqwqtx.html