4

I have activity A which have a ListView with custom adapter.

The custom adapter (which aplies to each list view item) have a button which invokes a custom dialog.

in this dialog an action is being performed which in response i want to invoke UI update on activity A.

This is my activity on resume code:

@Override
public void onResume() 
{
    super.onResume();
    setUI();  
}

But when the i call

dialog.dismiss();

The dialog closes without the Activity A OnResume method benig invoked.

How can i catch and update the activity ui?

Michael A
  • 5,770
  • 16
  • 75
  • 127
  • You can use [onDismmiss()](http://stackoverflow.com/questions/18830899/android-wait-for-user-input-at-alertdialog-to-proceed/18831531#18831531) – codeMagic Jun 19 '14 at 19:48
  • But my dialog is inside the adapter class not the activity class – Michael A Jun 20 '14 at 05:46

2 Answers2

7

You can set an OnDismissListener to your dialog to achieve this:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setOnDismissListener(listener);
...
Dialog dialog = builder.create();

You can let your Activity impelement DialogInterface.OnDismissListener and set them as the listener, so they get notified in the method onDismiss(DialogInterface dialog). In there, you can update your UI.

tknell
  • 9,007
  • 3
  • 24
  • 28
  • But my dialog is inside the adapter class not the activity class – Michael A Jun 20 '14 at 05:46
  • Well, it does not have to be your activity, you can also let your adapter implement the OnDismissListener and add it as a listener. – tknell Jun 20 '14 at 07:43
  • keep in mind this requires a min API level 17.. check this other solution for lower than 17 API levels.. http://stackoverflow.com/questions/13933077/android-setondismisslistern-for-api-lower-than-17 – json001 Sep 29 '14 at 03:18
-1

Actually its very easy - you can cast the Context inside the adapter to the calling containing activity:

ActivityName activity = (ActivityName )con;
activity.setUI();
Michael A
  • 5,770
  • 16
  • 75
  • 127