UI_延时播放

package com.example.time;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity {
	private TextView name;
	private int time;
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			if (time <=0) {
				start1();
				return;
			}
			time--;
			name.setText(time+"s");
			handler.sendEmptyMessageDelayed(1, 1000);
		}
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		time=9;
		name.setText(time+"s");
		handler.sendEmptyMessageDelayed(1, 1000);
		
	}
	private void initView() {
		name = (TextView) findViewById(R.id.name);
		name.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				start1();
			}
		});
	}
    //跳转
	private void start1() {
		startActivity(new Intent(MainActivity.this,Second_activity.class));
	};
}

猜你喜欢

转载自blog.csdn.net/u013628092/article/details/84106488
今日推荐