因此,只要我在我的設備上啓動我的應用程序,它運行良好,但是當我按下按鈕時,它什麼也不做,除非保持高調,然後彈出說它沒有響應這裏是代碼。我認爲它是我在OnClickListerner中擁有代碼的方式。包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.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();
@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);
set.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bSet:
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);
}
}
break;
}
}
}