码迷,mamicode.com
首页 > 其他好文 > 详细

Handler

时间:2016-09-05 16:51:45      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/jiang2538406936/p/5842562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!