警报需要多次

时间:2012-07-02 14:40:28

标签: android alarmmanager android-alarms repeatingalarm

我正在尝试制作一个警报应用程序,它将从用户那里花费'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();
    }

我不知道如何在运行时添加n个editTexts?对于AlarmManager类...我应该运行一个循环来创建n个AlarmManager个对象吗?

1 个答案:

答案 0 :(得分:0)

获取活动中listView / layout的引用。然后你可以使用layout.addView(editText)

它与Add button to a layout programmatically

几乎相同

西蒙