我正在尝试制作一个警报应用程序,它将从用户那里获取“n”次并在这些时间发出嗡嗡声并存储时间差异,以便下一个用户访问应用程序,存储的差异是默认值。这是主要活动的代码:
public void startAlert(View view) {
EditText textH = (EditText) findViewById(R.id.hours);
int h = Integer.parseInt(textH.getText().toString());
EditText textM = (EditText) findViewById(R.id.minutes);
int m = Integer.parseInt(textM.getText().toString());
EditText textS = (EditText) findViewById(R.id.seconds);
int s = Integer.parseInt(textS.getText().toString());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, h);
cal.set(Calendar.MINUTE, m);
cal.set(Calendar.SECOND, s);
Intent intent = new Intent(this, AlarmService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
}
我不知道如何editTexts
在运行时添加 n 个?对于AlarmManager
班级...我应该运行一个循环来创建 n 个AlarmManager
对象吗?