所以我整天都在做这个项目,因为我正在尝试了解 timePicker 并在 java 和 android sdk 中处理时间。所以现在我有以下设置:
package com.dicamillo.alarm;
import java.util.Calendar;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.TextView;
import android.widget.TimePicker;
public class AlarmlockActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
TimePicker tp;
Button set;
int hour;
int minuet;
DigitalClock dc;
Calendar calendar = Calendar.getInstance();
TextView complete;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tp = (TimePicker) findViewById(R.id.tpAlarmTime);
set = (Button) findViewById(R.id.bSet);
dc = (DigitalClock) findViewById(R.id.digitalClock1);
hour = calendar.get(Calendar.HOUR);
minuet = calendar.get(Calendar.MINUTE);
complete = (TextView) findViewById(R.id.tvTest);
set.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bSet:
Thread alarmstart = new Thread() {
public void run() {
while (tp.getCurrentHour().intValue() != hour
&& tp.getCurrentMinute().intValue() != minuet) {
tp.getCurrentHour().intValue();
tp.getCurrentMinute().intValue();
if (tp.getCurrentHour().intValue() == hour
&& tp.getCurrentMinute().intValue() == minuet) {
MediaPlayer mp = MediaPlayer.create(
AlarmlockActivity.this, R.raw.alarm);
mp.start();
complete.setText("COmpleted!");
}
}
}
};
alarmstart.start();
break;
}
}
and when the selected time reaches the current time nothing happens like it should supposed to. 我在线程中遗漏了什么吗?或者我这样做完全错误。任何帮助工作都很棒。我知道我今天一直在寻求很多帮助,但我只想学习。=)