dialogfragment

Where should onActivityResult be handled, dialog fragment, fragment, or activity?

匆匆过客 提交于 2019-11-30 09:52:36
问题 In my android app, I have a fragment where the user can add a picture, either from gallery or from camera. I've created an alert dialog and placed it in a DialogFragment. When the user chooses an option, I call startActivityForResult. My question is, where should ideally this result be handled? (i.e. where should i place onActivityResult?) In the DialogFragment class, the host fragment, or the host activity? Does it matter? 回答1: onActivityResult() will be invoked first on the Activity. After

BottomSheetDialogFragment - listen to dismissed by user event

大城市里の小女人 提交于 2019-11-30 00:39:43
问题 How can I listen to a FINAL dismissal of a BottomSheetDialogFragment ? I want to save user changes on the final dismissal only... I tried following: Method 1 This only fires, if the dialog is dismissed by swiping it down (not on back press or on touch outside) @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog d = super.onCreateDialog(savedInstanceState); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) {

懒人必备通用的Dialog弹窗sdk

会有一股神秘感。 提交于 2019-11-29 21:34:34
目录 前言 XDialog的由来 使用方法解析 框架原理解析 前言 我看到很多封装Dialog的,但是我觉得都有缺点,所以我也就取其中一个封装通用的弹窗Dialog出来,支持AndroidX,希望大家能给出宝贵的意见。 XDialog的由来 所有框架的由来都是为了更方便,更高效的解决问题,XDialog也一样,是为了在项目中更高效的实现项目的弹窗效果,XDialog是继承自DialogFragment进行封装的,大部分开发者在实现弹窗效果的时候,会首选系统提供的AlertDialog; 但是使用系统的Dialog在某些情况下会出现问题,最常见的场景是当手机屏幕旋转时Dialog弹窗会消失,并抛出一个系统,这个异常不会导致异常崩溃,因为Google开发者知道这个问题,并进行了处理. Dialog使用起来其实更简单,但是Google却是推荐尽量使用DialogFragment. 1.DialogFragment的优点 DialogFragment 本身是 Fragment 的子类,有着和 Fragment 基本一样的生命周期,使用 DialogFragment 来管理对话框,当旋转屏幕和按下后退键的时候可以更好的管理其生命周期 在手机配置变化导致 Activity 需要重新创建时,例如旋转屏幕,基于 DialogFragment 的对话框将会由 FragmentManager 自动重建

support.v4.app.DialogFragment使用问题总结

耗尽温柔 提交于 2019-11-29 18:19:22
因app需求问题,需要实现如图这种dialog 看到这里,你可能会说如此easy的事情,还说什么! 那么继续往下看! 场景1: import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; public class AlertDialogFragmentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity

Where should onActivityResult be handled, dialog fragment, fragment, or activity?

旧城冷巷雨未停 提交于 2019-11-29 16:20:33
In my android app, I have a fragment where the user can add a picture, either from gallery or from camera. I've created an alert dialog and placed it in a DialogFragment. When the user chooses an option, I call startActivityForResult. My question is, where should ideally this result be handled? (i.e. where should i place onActivityResult?) In the DialogFragment class, the host fragment, or the host activity? Does it matter? onActivityResult() will be invoked first on the Activity. After that it will be reached out to the Fragments, if you call super.onActivityResult() in your Activity. This is

What is lifecycle of DialogFragment

扶醉桌前 提交于 2019-11-29 13:47:38
问题 I could not find proper lifecycle of android.support.v4.app.DialogFragment by searching on Google. I need this for some implementation. As we know DialogFragment has some methods same like Dialog . DialogFragment extends Fragment so its lifecycle is same as Fragment . But what about other methods of DialogFragment ? Here is Fragment lifecycle. Can one provide for DialogFragment ? 回答1: DialogFragment life cycle is similar to the life cycle of fragment: . To test yourself put logs in each of

How to hide the onscreen keyboard when a DialogFragment is canceled by the setCanceledOnTouchOutside event

本秂侑毒 提交于 2019-11-29 04:02:56
If an edittext is currently focused and the user clicks outside of the DialogFragment; I want the on screen keyboard to disappear. I can get it to work for when the DialogFragment is dismissed this way: InputMethodManager imm; public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState) { imm = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); ...} @Override public void dismiss(){ imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); super.dismiss(); } However, if I try the same thing for when it is canceled by

Change DialogFragment enter/exit transition at just before dismissing

霸气de小男生 提交于 2019-11-28 18:12:23
I have a DialogFragment and i set animation for enter/exit in the onActivityCreated method as below @Override public void onActivityCreated(Bundle arg0) { super.onActivityCreated(arg0); getDialog().getWindow() .getAttributes().windowAnimations = R.style.DialogAnimation; } my DialogAnimation style files is as follows <style name="DialogAnimation"> <item name="android:windowEnterAnimation">@android:anim/fade_in</item> <item name="android:windowExitAnimation">@android:anim/fade_out</item> </style> This works for me now... Now my problem is i want to have two different exit animation one for when

Android 撸起袖子,自己封装 DialogFragment

妖精的绣舞 提交于 2019-11-28 14:01:29
前言 具体的代码以及示例我都放上 Github 了,有需要的朋友可以去看一下 DialogFragmentDemos ,欢迎 star 和 fork. 本文的主要内容 DialogFragment 是什么 创建通用的 CommonDialogFragment 实现各种类型的 DialogFragment 在写正文之前,先来一波效果展示吧 一、DialogFragment 是什么 DialogFragment 在 Android 3.0 时被引入,是一种特殊的 Fragment,用于在 Activity 的内容之上显示一个静态的对话框。例如:警告框、输入框、确认框等。 1、DialogFragment 的优点 其实在 Android 中显示对话框有两种类型可供使用,一种是 DialogFragment,而另一种则是 Dialog。在 DialogFragment 产生之前,我们创建对话框一般采用 Dialog,而且从代码的编写角度来看,Dialog 使用起来其实更加简单,但是 Google 却是推荐尽量使用 DialogFragment,是不是感觉很奇怪,其实原因也很简单, DialogFragment 有着 Dialog 所没有的非常好的特性 DialogFragment 本身是 Fragment 的子类,有着和 Fragment 基本一样的生命周期,使用

How to hide the onscreen keyboard when a DialogFragment is canceled by the setCanceledOnTouchOutside event

北慕城南 提交于 2019-11-27 18:00:04
问题 If an edittext is currently focused and the user clicks outside of the DialogFragment; I want the on screen keyboard to disappear. I can get it to work for when the DialogFragment is dismissed this way: InputMethodManager imm; public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState) { imm = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); ...} @Override public void dismiss(){ imm.hideSoftInputFromWindow(getView()