@SuppressLint("ValidFragment")
public final class DeleteEventDialog extends DialogFragment {
- private final Event event;
- private final Activity activity;
-
- public DeleteEventDialog(final Event event, final Activity activity) {
- super();
- this.event=event;
- this.activity=activity;
- }
+ private Event event;
+ public boolean deleted=false;
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ event=getArguments().getParcelable("Event");
builder.setMessage(R.string.askdeleteevent)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
event.delete(getActivity());
- activity.finish();
+ deleted=true;
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public class DisplayEventActivity extends Activity {
public static final String EXTRA_EVENT = "event";
private Event event;
+ private final DeleteEventDialog d=new DeleteEventDialog();
public static void displayEvent(final Context context, final Event event){
final Intent i=new Intent(context,DisplayEventActivity.class);
description.setText(event.description);
}
+ @Override
+ protected void onResume () {
+ super.onResume();
+ if(d.deleted)
+ finish();
+ }
+
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
final MenuInflater inflater = getMenuInflater();
// Handle item selection
switch (item. getItemId()) {
case R.id.deleteevent:
- final DeleteEventDialog d=new DeleteEventDialog(event,this);
+ final Bundle b=new Bundle();
+ b.putParcelable("Event",event);
+ d.setArguments(b);
d.show(getFragmentManager(), "Delete");
+
return true;
case R.id.eventlist:
final Intent it=new Intent(this,EventListActivity.class);
getListView().setSelectionFromTop(idx, 0);
}
+ @Override
+ protected void onStart() {
+ super.onStart();
+ displayEvents();
+ }
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);