postheadericon android chronometer example


Create an application that will display toast(Message) on specific interval of time


File Name : E8Activity.java


package bsr.exa;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Chronometer.OnChronometerTickListener;

public class E8Activity extends Activity {
/**
     *  @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.com
     *
     *  8) Create an application that will display toast(Message) on specific interval of time
     *  
     **/
Chronometer timer;
int i=0;
int Duretion=10;
TextView  txt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    timer=(Chronometer)findViewById(R.id.chronometer1);
    txt=(TextView)findViewById(R.id.txt);
   
    timer.start();
    timer.setOnChronometerTickListener(new OnChronometerTickListener() {

@Override
public void onChronometerTick(Chronometer arg0) {
// TODO Auto-generated method stubicon.png

txt.setText("Next Message will display after  [ "+(Duretion-(i+1))+" ] seconds ");
    i++;
    if(i>=Duretion)
    {
    Toast.makeText(E8Activity.this, "Message "+(i/10), 10000).show();
    Duretion+=10;
    }
}
});  
    }
}

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.