2

I made a dialog with builder.setSingleChoiceItem with array of items that a user can choose from. But when a user adds something to that array, the list in that dialog is not updated, showing the previous list.

I read that you need to recreate the dialog in order to achieve this goal. How do you recreate it? How do you destroy the dialog and recreate its content all over again? so that you can refresh the list?

Thanks a lot for your answer in advance.

coolcool1994
  • 3,704
  • 4
  • 39
  • 43
  • 2
    Make sure when dialog is created, latest data is being passed to it. Problem may lie in the adapter being passed to the list in dialog. Please put some code for better understanding. – Usama Sarwar Jan 21 '13 at 12:13
  • First time dialog is created, the array is updated, but not the second time. Not the second time or other times afterward. For example, if you add something to that array and open the dialog for the second time, the array is updated but the list that uses this array is not updated. I don't think you can update this unless you recreate the dialog, by destroying it and recreating it – coolcool1994 Jan 21 '13 at 13:35
  • Have yoo tried notifyDataSetChanged()on adapter being used ? – Usama Sarwar Jan 21 '13 at 13:41
  • notifyDataSetChanged() could work but I didn't try it. I mean, I use notifyDataSetChanged for spinners but can you also use that for dialog. Anyone, successfully able to do it, please reply here. – coolcool1994 Jan 22 '13 at 03:16

1 Answers1

1

I found the answer

    @Override
    public void onPrepareDialog(int id, Dialog dialog) 
    {
        switch(id) 
        {
//name of the case of the dialog you want to REFRESH -meaning destroy and recreate
            case REMOVE_WATCH_WORD :
                removeDialog(REMOVE_WATCH_WORD);
                break;

        }
     }

I found a way to do this. In order to recreate your dialog every time in order to refresh everything, title, list, array, everything in the dialog, remove your dialog in onPrepareDialog. This will allow ALL the values to be reset, because onCreate dialog will be called again. This is the best, easy way solve this.

coolcool1994
  • 3,704
  • 4
  • 39
  • 43