Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Thursday, 18 October 2012

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

Pro8Activity.java
package ps.pro8;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.Chronometer.OnChronometerTickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Pro8Activity extends Activity implements OnClickListener, OnChronometerTickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText editsec;
 Button btclick;
 TextView msg;
 Chronometer timer;
 int sec=0,delay=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        editsec=(EditText) findViewById(R.id.editTextsec);
        btclick=(Button) findViewById(R.id.buttonclick);
        msg=(TextView) findViewById(R.id.textViewmsg);
        timer=(Chronometer) findViewById(R.id.chronometer1);
        
        timer.setVisibility(-1);
        
        btclick.setOnClickListener(this);
        timer.setOnChronometerTickListener(this);
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btclick.getId())
  {
   delay=Integer.parseInt(editsec.getText().toString());
   sec=0;
   timer.start();
  }
 }
 @Override
 public void onChronometerTick(Chronometer arg0) {
  // TODO Auto-generated method stub
  
  msg.setText("Text Next Message is [ 0"+ (delay-sec) +" ] sec delay");
  sec++;
  if(sec==delay)
  {
   sec=0;
   Toast.makeText(this, "Heres The Message...", Toast.LENGTH_SHORT).show();
  }
 }
}

2 comments:

  1. Hello Programmers,

    Thanks for this program. Today is my exam and you saved me.

    Thanks once again,
    SolveMyHow

    ReplyDelete
  2. i have error on this [timer.setVisibility(-1);] please help me to resolve it.

    ReplyDelete