0

I'm developing a small Android app and am having trouble with one small feature. I want to have a button invoke a series of Dialogs that the user can select a series of options for. For example, pressing the button will bring up a Dialog with 2 choices, pressing either of those choices will open another dialog with 2 more choices. When the user presses a button there, I want the 2 choices to be remembered somewhere.

I initially approached it by making 2 classes that extend DialogFragment and then showing DialogFragment #2 after a choice has been made in #1 but it seems a bit messy and I can't seem to save the 'path', ie: I want an int ranging from 0 to 4 representing the possible paths they could have done with 2 buttons in Dialog #1 and 2 buttons in Dialog #2, so essentially #2 would have to know what choice was made from #1.

Any tips? Cheers.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51
micnguyen
  • 1,419
  • 18
  • 25

2 Answers2

0

You can use shared preferences to store say, the text if the button clicked in dialog1, so that you can access that from dialog2, and so on. Just keep appending the text unique to the dialog fragment at each stage to that shared preference.

At any stage, you can retrieve the shared preference, and thus, you would have the path taken by the user amongst the dialogs.

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • Thanks for that. I initially considered SharedPreferences but I thought it was unnecessary for the simple task that I was doing. I ended up just creating 2 classes that extended DialogFragments and called #2 from #1 when a selection was made and referenced a global variable. Thanks anyway! – micnguyen Jan 22 '14 at 03:50
0

Here is what you looking for (hopefully!) otherwise take it as tips!!

You have best solution for your problem, Just use this WizardPager in your dailogfragment, thats it.

WizardPager:

enter image description here enter image description here

Just use this Roman nurik's Android-WizardPager

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
  • Thanks for that link! That is indeed a bit overkill for what I wanted to do, but that library looks great and coming from Roman Nurik you know it's going to be great. I might consider using it in the future. Thanks! – micnguyen Jan 22 '14 at 03:51