首页 > 代码库 > 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