dialogfragment

DialogFragment callback on orientation change

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm migrating my dialogs, currently using Activity.showDialog(DIALOG_ID); , to use the DialogFragment system as discussed in the android reference . There's a question that arose during my development when using callbacks to deliver some event back to the activity/fragment that opened the dialog: Here's some example code of a simple dialog: public class DialogTest extends DialogFragment { public interface DialogTestListener { public void onDialogPositiveClick(DialogFragment dialog); } // Use this instance of the interface to deliver action

How to properly retain a DialogFragment through rotation?

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a FragmentActivity that hosts a DialogFragment. The DialogFragment perform network requests and handles Facebook authentication, so I need to retain it during rotation. I've read all the other questions relating to this issue, but none of them have actually solved the problem. I'm using putFragment and getFragment to save the Fragment instance and get it again during activity re-creation. However, I'm always getting a null pointer exception on the call to getFragment in onRestoreInstanceState. I would also like to keep the dialog from

Android中Dialog与DialogFragment的对比

a 夏天 提交于 2019-12-02 21:38:44
最近学习对话框时发现有两种类型的可供使用,一种是Dialog,另一种则是Android 3.0 引入的基于Fragment的DialogFragment。 从代码的编写角度看,Dialog使用起来要更为简单,但是Google则是推荐尽量使用DialogFragment(对于Android 3.0以下的版本,可以结合使用support包中提供的DialogFragment以及FragmentActivity)。今天试着用这两种方式来创建对话框,发现DialogFragment果然有一个非常好的特性(在手机配置变化,导致Activity需要重新创建时,例如旋屏,基于DialogFragment的对话框将会由FragmentManager自动重建,然而基于Dialog实现的对话框则没有这样的能力)。 下面是两段实例代码: 他们使用的界面都一样:(dialog.xml) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation=

How to take text input with DialogFragment in Android?

南楼画角 提交于 2019-12-01 10:40:26
I am trying to get a value that user enters into a Dialog, using the recommended DialogFragment class for it, the Dialog constructs and runs fine, but I cannot return the value of the EditText parameter to the parent class, without get a Null pointer exception. My DialogHost class, this constructs, returns and links the parent to its buttons. package jo.app.co; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; public

BottomSheetDialogFragment - listen to dismissed by user event

这一生的挚爱 提交于 2019-12-01 02:23:24
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) { BottomSheetDialog d = (BottomSheetDialog) dialog; FrameLayout bottomSheet = (FrameLayout) dialog

AutoCompleteTextView allow only suggested options

南楼画角 提交于 2019-11-30 19:04:52
I have a DialogFragment that contains AutoCompleteTextView , and Cancel and OK buttons. The AutoCompleteTextView is giving suggestions of usernames that I'm getting from server. What I want to do is to restrict the user to be able to enter only existing usernames. I know I can do check if that username exists when the user clicks OK , but is there some other way, let's say not allow the user to enter character if there doesn't exist such username. I don't know how to do this because on each entered character I'm getting only up to 5 suggestions. The server is implemented that way. Any

DialogFragment with custom ListView

与世无争的帅哥 提交于 2019-11-30 14:07:42
I'm trying to create a DialogFragment that shows a dialog with a custom ListView inside. public class MultiSelectDialogCustom extends DialogFragment { ListView mLocationList; private ArrayList<String> mOfficeListItems = new ArrayList<String>(); public static MultiSelectDialogCustom newInstance(int title) { MultiSelectDialogCustom dialog = new MultiSelectDialogCustom(); Bundle args = new Bundle(); args.putInt("title", title); dialog.setArguments(args); return dialog; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Collections

What is lifecycle of DialogFragment

ε祈祈猫儿з 提交于 2019-11-30 13:53:14
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 ? DialogFragment life cycle is similar to the life cycle of fragment: . To test yourself put logs in each of the overrided methods of dialogFragment and then run your code you will understand the working of

DialogFragment 不可取消和点击外部不消失

旧街凉风 提交于 2019-11-30 13:22:25
在最近的项目开发中需要通过短信验证码登录,实现中需要用到DialogFragment来实现验证码输入框,具体效果如下图: TIM图片20170921105551.jpg 但是在具体使用过程中可能不小心触碰到透明背景,导致DialogFragment触发消失,那么怎么屏蔽呢? 原先在Activity显示Dialog,直接设置就可以了。如下所示: alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); 那么在DialogFragment并没有这样的方法,应该怎么实现呢?经过谷歌一番之后,找到了 网上的做法 http://blog.csdn.net/guijiaoba/article/details/50680726 这篇文章的方法,确实也可以实现,但是总感觉很复杂。 我们的做法 经过一番摸索之后,我发现在DialogFragment中有一个getDialog的方法,返回的是DialogFragment中的Dialog对象,那么现在我只需要操作这个Dialog对象就行; 在使用的时候: DialogFragment.getDialog.setCancelable(false); DialogFragment.getDialog.setCanceledOnTouchOutside

DialogFragment has blue line on top in Android 4.4.2

强颜欢笑 提交于 2019-11-30 13:03:01
There's a blue line appearing on top of my dialog fragment that I can't get rid off(I don't even know why does it appear in the first place. Does anybody know on how to get rid of this? I have tested it on several devices and it works just fine on later Android versions. My code: private void setupDialog() { final Dialog dialog = getDialog(); final Window window = dialog.getWindow(); window.setBackgroundDrawable(new ColorDrawable(0)); window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } layout: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=