因此,每当我在我的设备上启动我的应用程序时,它运行良好,但是当我按下按钮时,它什么也不做,除了保持高亮,然后弹出说它没有响应这里是代码。我认为这是我在 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;
}
}
}