画面にラベルのカウントダウンを表示する60秒をカウントダウンし、60秒後に写真を表示するアプリを作成したいと思います。時計/タイマーセクションの定義に問題があります。どんな体でも私を助けることができますか?
2594 次
2 に答える
0
You can use the CountDownTimer class: (just like in the example:)
public class Countdown extends Activity {
private TextView txtStatus;
private ImageView image;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
public void onResume() {
super.onResume();
setContentView(R.layout.main);
this.txtStatus = (TextView) this.findViewById(R.id.tv);
this.image = (ImageView) this.findViewById(R.id.image);
new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
txtStatus.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
image.setVisibility(View.VISIBLE);
}
}.start();
}
}
layout:
<?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/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="60"
/>
<ImageView android:layout_height="wrap_content" android:visibility="gone"
android:src="@drawable/icon" android:layout_width="wrap_content" android:id="@+id/image"></ImageView>
</LinearLayout>
于 2011-08-08T15:59:47.563 に答える
0
- variable(def) ブロックを用意して、1 に設定します。
- 時計の間隔を 1000 (1 秒) にする
- 時計が起動するたびに (タイマー イベント ブロック)、変数に 1 を追加します (変数ブロックは変数ブロックの値 + 1 に設定されます)。
- 次に、タイマー イベント内で、変数の値が 60 かどうかを確認します。60 の場合は、画像を表示し、タイマーを無効にします。
于 2011-09-12T13:52:40.883 に答える