Code ส่วนของ 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" > <TextView android:id="@+id/showCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge"> </TextView> </LinearLayout>
Code ส่วนของ Java
package slayer.countdown; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.os.CountDownTimer; public class CountDownActivity extends Activity { private TextView mTextField; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextField = (TextView)findViewById(R.id.showCount); new CountDownTimer(30000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " + millisUntilFinished / 1000); } public void onFinish() { mTextField.setText("done!"); } }.start(); } }
ไม่มีความคิดเห็น:
แสดงความคิดเห็น