Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

android - Should I use a PopupWindow or DialogFragment for accepting input?

I am doing a Popup with 3 Spinners and an EditText. After reading many blogs and articles I can't decide which is the best option, PopupWindow or DialogFragment.

The criteria would be:

  1. Compatibility with different Android's versions
  2. Performance

If there is a better way to do it I am open to change the perspective.

Thank you very much.

DialogFragment:

  • Pros:
  • Cons:

PopupWindow:

  • Pros:
  • Cons:

EDIT: CONCLUSION

DialogFragment allows you to use more complex features. Another important thing is that it is more tablet-friendly as it lets user to have opened more than one fragment at a time. Fragments are a more dynamic solution and they are the standard for newer Android versions.

PopupWindow is simpler and it is very helpful on simple questions to the user.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The support library can give you a DialogFragment which is compatible with old versions of android. Go ahead with the fragment dialog cuz what you're asking is pretty specifical (3 spinners and an edittext. Just right click your project and press on "Android tools" --> "Add support library" Make sure when you use the dialog to import

import android.support.v4.app.DialogFragment;

Else you'll end up using the dialog without the support :P. You will have more flexibility with the dialog fragment and the power to use the view you see fit (even a layout made by yourself) without much effort.

Dialog Fragment

Pros:

  • Capable of adding any view
  • Easy to edit
  • Can be adapted to tablets or cellphones in landscape or portrait just by modifying the layout
  • Can dedicate a whole new class just to modify it your way

Cons:

  • Cosumes more memory the more complex is your view
  • Harder to code

Popup Window:

Pros:

  • Simpler
  • Easier to code
  • It's more standard so it'll be harder for the user to be confused with it

Cons:

  • Simpler, which means less control over it
  • Limited to a few templates

These are just from the top of my mind and from my experience, but you should read the documentation

http://developer.android.com/reference/android/widget/PopupWindow.html

http://developer.android.com/reference/android/app/DialogFragment.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...