CountDownTimer倒计时

来源:互联网 发布:ug复杂模具编程思路 编辑:程序博客网 时间:2024/05/23 01:53
直接上代码public class MainActivity extends Activity {    private TextView text;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        text = ((TextView) findViewById(R.id.text));        timer.start();    }    private CountDownTimer timer=new CountDownTimer(6000,1000) {        @Override        public void onTick(long l) {            text.setText((l/1000)+"秒后可重发");        }        @Override        public void onFinish() {            text.setText("获取验证码");        }    };}xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">    <TextView        android:id="@+id/text"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></RelativeLayout>
 
0 0
原创粉丝点击