Why Android DialogFragment confuses me – part 1

Evelina Vrabie

Dedicated coder, occasional blogger, hackathon goer and friendly team mate.

You may also read...

  • Suman

    Nice article.

  • http://www.andreamaglie.com Andrea Maglie

    Intresting article! I’ve made a tool to generate the code for a Fragment and it can be used also for DialogFragments: http://www.andreamaglie.com/android-fragment-generator/index.html

  • Scott

    How did you end up getting the buttons to be styled? I’m having the exact problem you’ve described and cannot figure out a solution. I used to get the buttons in the onStart() method via getDialog().getButton() and then call .setBackground(), but as soon as I added an overall style it started ignore that background I was setting, and adding a default background to the master style doesn’t seem to do the trick either.

  • http://fiisportiv.ro Gratian

    I`m sorry, i just saw that there is a part 2. Please don`t get into consideration the previous mail.

  • http://fiisportiv.ro Gratian

    Did you manage to fix this issue? Is there a part 2? I`m stuck with this problem.

  • http://danlew.net Dan Lew

    Maybe you’re going to get to it eventually, but what about Fragment.setArguments()? That way you don’t have to muck around with setRetainInstance() but you still get constructor variables.

    • http://evelina.vrabie.info/ Evelina Vrabie

      Yes, I know about setArguments. You can pass a Bundle to it so the restrictions I mentioned still apply. What do you mean by “still get constructor variables” with setArguments()?

      • http://danlew.net Dan Lew

        What I meant with setArguments() is that you can do something like create a single DialogFragment that takes arguments. It’s the way around not being able to declare a constructor with parameters, since Android requires a default constructor for Fragments.

        Also, I didn’t understand fully what you were trying to do – apply listeners. I mostly work by making onAttach() pick up the parent Fragment/Activity and trying to apply a single listener Interface to it. That way you don’t have to pass anything to the Fragment but it can still communicate back to whoever created it. That takes care of wiring while setArguments() can take care of parameters.

        • http://evelina.vrabie.info/ Evelina Vrabie

          Yes, I am aware of that approach, I use something similar here: http://goo.gl/oq7l1E
          I just wanted to pinpoint the pitfalls other developers might fall into with passing listeners as parameters, which is something I see again and again.

  • Pingback: Why Android DialogFragment confuses me - part 2()

  • http://alchemiasoft.wordpress.com/ Simone

    Hi Evelina,
    don’t forget to mention this one:
    https://code.google.com/p/android/issues/detail?id=23761

    Cheers,
    Simone

    • http://evelina.vrabie.info/ Evelina Vrabie

      Ah yes, thank you Simone I will add a couple more in the next post.