Should I use a PopupWindow or DialogFragment for accepting input?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 09:45:16

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

If you need EditText in your window and want to let your user to be able to longpress in it and paste (normal behaviour of an edit-text) then do not use popupwindow, I found it in hard way so:

A pretty Big Cons on popupwindow is that long press on edit-text wont bring default context menu (copy/paste/select all,...).also some reported in some devices this actually causes an app crash. see this https://code.google.com/p/android/issues/detail?id=62508

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!