开发者

How can I recreate a dialog, including its whole content?

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 m开发者_运维知识库e 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.OnShowListener to 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 call notifyDatasetChanged() on its adapter. Or just set the adapter once again mAlertdlg.getListView().setAdapter(list)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜