0

I am using an alertdialog to add a new contact and inside is a button which is supposed to let the user choose a picture source, either from taking a picture or selecting one from the gallery. If I use startActivity from inside the alertdialog, would I be able to return to the alertdialog without the alertdialog closing? I tried adding another dialog to the dialog in other fields for input validation but the alertdialog seems to close before the other popup shows up.

louieansonng
  • 343
  • 2
  • 7
  • 17

2 Answers2

0

You can simply have your dialog extend Activity instead of Dialog. Then apply the dialog theme to that activity. See Android Activity as a dialog

Community
  • 1
  • 1
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
0

You should use Activity in Dialog Mode for this. AlertDialog is not supposed to do what you are doing and yes it will close and lose its context.

Here is how to do it.

<activity android:name=".MyDialogActivity" 
        android:theme="@android:style/Theme.Dialog" 
        android:configChanges="keyboardHidden|orientation|keyboard"></activity>
PravinCG
  • 7,688
  • 3
  • 30
  • 55
  • Yes this is part of the manifest and it essentially opens the activity as a dialog and will behave like an activity. So now you can call startActivityForResult to get the new pictures and in onActivityResult receive the new picture. – PravinCG May 11 '11 at 08:27
  • How about the buttons like saving and cancelling? Will I have to put those on the layout or can I use something like setPositiveButton and setNegativeButton? – louieansonng May 11 '11 at 08:32
  • Add as many buttons as you want in the layout and if you find the answer helpful go ahead and accept it or else people might not answer your future queries. – PravinCG May 11 '11 at 08:46
  • Last question, how do I put a header line between the title and the view? – louieansonng May 11 '11 at 08:53
  • In the layout add a TextView on the top and add a suitable background this should do the trick. – PravinCG May 11 '11 at 09:00