如何在android报警中设置重复周日

时间:2013-12-28 11:50:21

标签: android alarm

我正在制作一个警报应用程序。在这个应用程序中我设置周日的问题。在这里我使用带复选框的对话框。当我选择一个盒子而不是它的设置但是如果我选择两个或多个盒子而不是覆盖所有盒子而设置最后一个复选框意味着它只设置一次警报。

我的代码在这里,请以任何方式告诉我我做的事情......

   final String days[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
AlertDialog.Builder weekDialog=new AlertDialog.Builder(SetAlarm.this);
weekDialog.setTitle("Select repeat days");
weekDialog.setMultiChoiceItems(days, null, new DialogInterface.OnMultiChoiceClickListener() {

    @Override
    public void onClick(DialogInterface d, int pos, boolean isChecked) {
        // TODO Auto-generated method stub

    }

});
weekDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub
        SparseBooleanArray CheCked = ((AlertDialog) arg0).getListView().getCheckedItemPositions();

        if (CheCked.get(0))
        {
            forday(2);
        }
        if (CheCked.get(1))
        {
            forday(3);
        }
        if (CheCked.get(2))
        {
            forday(4);
        }
        if (CheCked.get(3))
        {
            forday(5);
        }
        if (CheCked.get(4))
        {
            forday(6);
        }
        if (CheCked.get(5))
        {
            forday(7);
        }
        if (CheCked.get(6))
        {
            forday(1);
        }
        Toast.makeText(SetAlarm.this, "week day has been selected", Toast.LENGTH_SHORT).show();
    }
});

 weekDialog.show();
 }
 private void forday(int week) {
// TODO Auto-generated method stub
c.set(Calendar.DAY_OF_WEEK, week);
c.set(Calendar.HOUR_OF_DAY, h);
c.set(Calendar.MINUTE, m);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);

if (c.before(Calendar.getInstance())) {
c.add(Calendar.WEEK_OF_MONTH, 1);
}

0 个答案:

没有答案