首页 > 代码库 > Handler
Handler
package com.example.administrator.mytestapp.Handler;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.ProgressBar;import com.example.administrator.mytestapp.R;import java.util.Timer;import java.util.TimerTask;public class TextHandler extends AppCompatActivity {private static final int MSG_TAG=0x1234; private int progress=0; private ProgressBar largebar=null; private Handler BarHandler=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text_handler); largebar= (ProgressBar) findViewById(R.id.largebar); BarHandler=new Handler() { @Override public void handleMessage(Message msg) { if (msg.what==MSG_TAG) { if (progress==100) { progress=0; }else { progress+=4; } largebar.setProgress(progress); } } }; new Timer().schedule(new TimerTask() { @Override public void run() { Message msg=new Message(); msg.what=MSG_TAG; BarHandler.sendMessage(msg); } },0,500); }}
Handler
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。