所以我想用一个按钮来引导一个新的活动,可以选择两个整数(小时和分钟),而不是设置闹钟。或者也许做些不同的事情来获取这些整数的价值并改变它们?有没有更好的方法来编码?使用按钮触发闹钟
我的代码到目前为止是这样的 - 我是否做得到目前为止?
public class AlarmPtest extends Activity implements android.view.View.OnClickListener{
/** Called when the activity is first created. */
Button SetAlarm, SetTimer;
int hours = 1, min = 30;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Vars();
}
private void AlarmClock() {
// TODO Auto-generated method stub
Intent i = new Intent(android.provider.AlarmClock.ACTION_SET_ALARM);
i.putExtra(android.provider.AlarmClock.EXTRA_HOUR, hours);
i.putExtra(android.provider.AlarmClock.EXTRA_MINUTES, min);
startActivity(i);
}
private void Vars() {
// TODO Auto-generated method stub
SetAlarm = (Button) findViewById(R.id.SetAlarm);
SetTimer = (Button) findViewById(R.id.TimerAlarm);
SetAlarm.setOnClickListener(this);
SetTimer.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.SetAlarm:
Toast alarmToast = Toast.makeText(this, "you click alarm", Toast.LENGTH_LONG);
alarmToast.show();
AlarmClock();
case R.id.TimerAlarm:
Toast TimerToast = Toast.makeText(this, "you get 15 min", Toast.LENGTH_LONG);
TimerToast.show();
hours = 0 ;
min = 15;
AlarmClock();
}
}
}
好的,谢谢! :)它不会让我添加一个点,因为我太新,但是。那么我应该通过一个不同的事件吗?或者只是在同一个类中使用一个函数 – domshyra
不需要通过不同的类传递它,只需在现有类中使用这些函数即可。祝你好运 – Entreco