private void fillRepeatList() { RepeatSchedule rs; RepeatAdapter ra = (RepeatAdapter) getListAdapter(); ra.clear(); int[] ids = RepeatSchedule.getRepeatIds(); if (ids != null) { for (int id : ids) { rs = RepeatSchedule.getSchedule(id); if (rs == null) { continue; } rs.trans = rs.getTransaction(); if (rs.trans == null) { continue; } if (mAccountId != 0 && rs.trans.account != mAccountId) { continue; } ra.add(rs); } } ra.notifyDataSetChanged(); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; try { info = (AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG + ".onCreateContextMenu()", "Bad ContextMenuInfo", e); return false; } int id = (int) getListAdapter().getItemId(info.position); final RepeatSchedule rs = RepeatSchedule.getSchedule(id); switch (item.getItemId()) { case CONTEXT_EDIT: editRepeat(id); break; case CONTEXT_DELETE: AlertDialog dialog = new AlertDialog.Builder(this) .setMessage("Are you sure you wish to delete this repeat schedule?") .setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { rs.erase(true); fillRepeatList(); } }) .setNegativeButton( R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {} }) .create(); dialog.show(); break; } return true; }