main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Chronometer android:visibility="invisible"
android:layout_height="wrap_content" android:text="Chronometer"
android:id="@+id/chronometer1"
android:layout_width="122dp"></Chronometer>
</LinearLayout>
Tut_2_3Activity.java
package com.tut2_3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;
import android.widget.Toast;
import android.widget.Chronometer.OnChronometerTickListener;
public class Tut_2_3Activity extends Activity implements
OnChronometerTickListener {
/** Called when the activity is first created. */
Chronometer cMeter;
int i=0;
int cnt=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cMeter=(Chronometer)findViewById(R.id.chronometer1);
cMeter.setOnChronometerTickListener(this);
cMeter.start();
}
@Override
public void onChronometerTick(Chronometer chronometer) {
// TODO Auto-generated method stub
i++;
if(i==5)
{
cnt++;
Toast.makeText(this,"Message :
"+cnt,2000).show();
i=0;
}
}
}
Output
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Chronometer android:visibility="invisible"
android:layout_height="wrap_content" android:text="Chronometer"
android:id="@+id/chronometer1"
android:layout_width="122dp"></Chronometer>
</LinearLayout>
Tut_2_3Activity.java
package com.tut2_3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;
import android.widget.Toast;
import android.widget.Chronometer.OnChronometerTickListener;
public class Tut_2_3Activity extends Activity implements
OnChronometerTickListener {
/** Called when the activity is first created. */
Chronometer cMeter;
int i=0;
int cnt=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cMeter=(Chronometer)findViewById(R.id.chronometer1);
cMeter.setOnChronometerTickListener(this);
cMeter.start();
}
@Override
public void onChronometerTick(Chronometer chronometer) {
// TODO Auto-generated method stub
i++;
if(i==5)
{
cnt++;
Toast.makeText(this,"Message :
"+cnt,2000).show();
i=0;
}
}
}
Output
No comments:
Post a Comment