Handler
Posted 一个不愿透漏姓名的朝阳群众叫旺仔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章