@Override public void onClick(View v) { // Ignore all clicks on the list once a dialog has been // created. This is needed to guard against quikly pressing // the buttons multiple times. if (mDialog != null && mDialog.isShowing()) { return; } int id = v.getId(); if (id == R.id.button_remove_repeat) { int iList = (Integer) v.getTag(); mListData.remove(iList); mListAdapter.notifyDataSetChanged(); } else if (id == R.id.button_add_new) { // Find a new value for the repeat and add a // repeat item based on it. This is done by simply // adding the default repeat value to the maximum // value in the list and then bounding it using the // maximum repeat value (which is max(duration) - 1) int maxRepeat = 0; for (int i = LIST_POS_REPEAT_START; i < mListData.size(); i++) { int repeat = mListData.get(i); if (repeat > maxRepeat) { maxRepeat = repeat; } } int duration = mListData.get(LIST_POS_DURATION); maxRepeat += NotifConfig.defaultRepeat; if (maxRepeat >= duration) { maxRepeat = duration - 1; } // Add the new repeat item to the list mListData.add(LIST_POS_REPEAT_START, new Integer(maxRepeat)); mListAdapter.notifyDataSetChanged(); } else if (id == R.id.trig_edit_done) { // Copy the values from the UI to the description class, // convert to string and then send back the result mNotifDesc.setDuration(mListData.get(LIST_POS_DURATION)); mNotifDesc.setSuppression(mListData.get(LIST_POS_SUPPRESSION)); if (LIST_POS_REPEAT_START < mListData.size()) { mNotifDesc.setRepeats(mListData.subList(LIST_POS_REPEAT_START, mListData.size())); } else { mNotifDesc.setRepeats(new ArrayList<Integer>()); } Intent intent = new Intent(); intent.putExtra(KEY_NOTIF_CONFIG, mNotifDesc.toString()); setResult(0, intent); finish(); } else if (id == R.id.trig_edit_cancel) { finish(); } }