我应该使用PopupWindow还是DialogFragment来接受输入?

19
我正在使用3个Spinner和一个EditText制作一个弹出窗口。在阅读了许多博客和文章后,我无法决定哪种选项是最好的,是PopupWindow还是DialogFragment。
标准如下:
1.与不同Android版本的兼容性 2.性能
如果有更好的方法,我愿意改变视角。
非常感谢。
DialogFragment:
优点: 缺点:
PopupWindow:
优点: 缺点:

编辑:结论

DialogFragment 允许您使用更复杂的功能。另一个重要的事情是它更适合平板电脑,因为它允许用户同时打开多个片段。片段是一种更动态的解决方案,也是新版 Android 的标准。

PopupWindow 更简单,对于向用户提出简单问题非常有帮助。


你做了哪些决定,以便将其缩小到其中一种(您知道任何优缺点吗?)。此外,考虑发布您想要的图片。这些更改将使其成为全明星帖子。 - Phil
谢谢Phil,我会尽力改进问题的! - Daniel
2个回答

31
支持库可以提供与旧版本的Android兼容的DialogFragment。继续使用片段对话框,因为您所要求的是非常特定的内容(3个下拉菜单和一个编辑文本)。只需右键单击您的项目,然后按“Android工具”-->“添加支持库”确保在使用对话框时导入。
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


1
如果您需要在窗口中使用EditText,并希望让用户能够长按并粘贴(这是编辑文本的正常行为),则不要使用popupwindow。我是通过艰难的方式发现这一点的。 popupwindow的一个相当大的缺点是,长按编辑文本不会出现默认的上下文菜单(复制/粘贴/全选等)。还有一些报告称,在某些设备上,这实际上会导致应用程序崩溃。请参见此https://code.google.com/p/android/issues/detail?id=62508

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接