In my app I have 2 tabs. Each tab showing a different Activity.
In activity_1 I manage a global array of strings – add and delete options are available.
In activity_2 I have an AlertDialog.
The dialog is created by calling the Activity’s dialog’s functions: onCreateDialog, onPrepareDialog.
The dialog shows a multiple-choice list and the list’s source is the global array that activity_1 manages.
The problem: I would like to display the updated list in the dialog of activity_2, according to the changes made to the global array in activity_1. The problem is that the list is created in onCreateDialog, and this method gets called only once in the activity’s lifecycle.
For example: If the global array contains: [“Banana”, “Orange”] and in activity_1 I’ve just added: “Apple”, and I clicked tab #2, I would like activity_2 to open the dialog and display in the dialog list: [“Banana”, “Orange”, “Apple”].
I’ve tried to repopulate the list in: onPrepareDialog but with no success, it’s just allowing me to decide which of the list items will be checked or not. Should I extend AlertDialog?
Any help will be appreciated.
You can use
DialogInterface.OnShowListenerto update the dialog content every time it gets displayed.Edit:
You will have to implement a listadpater and set the adapter to the builder.
In onPrepareDialog, get the listview
mAlertdlg.getListView()and callnotifyDatasetChanged()on its adapter. Or just set the adapter once againmAlertdlg.getListView().setAdapter(list)