This program is for count down in android
Step 1) Your main java file is here
package count.down;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
public class CountdownActivity extends Activity {
/** Called when
the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView
myCounter = (TextView)findViewById(R.id.mycounter);
new
CountDownTimer(50000, 1000) {
@Override
public void
onFinish() {
// TODO
Auto-generated method stub
myCounter.setText("Finished!");
}
@Override
public void
onTick(long millisUntilFinished) {
// TODO
Auto-generated method stub
myCounter.setText("Millisecond Until Finished: " +
String.valueOf(millisUntilFinished));
}
}.start();
}
}
Step 2) Your main.xml file is here.
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/mycounter"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
No comments:
Post a Comment