Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.os.CountDownTimer;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- Counter crt;
- TextView tvCtr;
- Button btn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- btn = (Button) findViewById(R.id.start);
- tvCtr = (TextView) findViewById(R.id.tvCtr);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //10000 = 10 seconds
- crt=new Counter(10001,1);
- crt.start();
- }
- });
- }
- public class Counter extends CountDownTimer {
- Counter(long mSeconds,long range){
- super(mSeconds,range);
- }
- @Override
- public void onTick(long millisUntilFinished) {
- tvCtr.setText(String.valueOf(millisUntilFinished/1000));
- }
- @Override
- public void onFinish() {
- tvCtr.setText("Done");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement