I ran into the same problem:
Two solutions:
1 / Fast and dirty
Delete the dialog every time you are done with it => onPrepareDialog will not be called, so you will not have problems updating the data:
protected Dialog onCreateDialog(int id) { ... case DIALOG_REVIEW: { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(names.get(position) + " number(s)"); dialog.setSingleChoiceItems(phoneNums, 0,new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int which) {
if you prefer, you can put onDismissListener and remove removeDialog in the dialog box.
2 / Pretty pretty
In the onPrepareDialog method, simply replace the old ArrayAdapter used by the dialog with a new fresh one:
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case DIALOG_REVIEW: ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.select_dialog_singlechoice, android.R.id.text1, phoneNums); AlertDialog ad = (AlertDialog) dialog; ad.getListView().setAdapter(adapter); break; default: super.onPrepareDialog(id, dialog); } }
I use the same method as the one used by android (AlertController.java L. 854 froyo source code) to populate the dialog for the first time.
ol_v_er
source share