android-dialogfragment

IllegalStateException( “You can not set Dialog's OnCancelListener or OnDismissListener”)

浪子不回头ぞ 提交于 2019-11-27 17:07:32
问题 This DialogFragment implementation causes an IllegalStateException( "You can not set Dialog's OnCancelListener or OnDismissListener") . Why? Solution? public class OkCThreadDialog1 extends DialogFragment{ DialogInterface.OnCancelListener onCancelListener; public OkCThreadDialog1(){ } public static OkCThreadDialog1 newInstance(String title, String message) { OkCThreadDialog1 frag = new OkCThreadDialog1(); Bundle args = new Bundle(); args.putString("title", title); args.putString("message",

Show DialogFragment from onActivityResult

人走茶凉 提交于 2019-11-27 16:55:28
I have the following code in my onActivityResult for a fragment of mine: onActivityResult(int requestCode, int resultCode, Intent data){ //other code ProgressFragment progFragment = new ProgressFragment(); progFragment.show(getActivity().getSupportFragmentManager(), PROG_DIALOG_TAG); // other code } However, I'm getting the following error: Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState Anybody know what's going on, or how I can fix this? I should note I'm using the Android Support Package. If you use Android support library, onResume method

DialogFragment throws ClassCastException if called from Fragment

﹥>﹥吖頭↗ 提交于 2019-11-27 16:49:26
问题 My DialogFragment throws ClassCastException if called from Fragment, while it is working normally if called from an Activity. I have already looked at few other questions with similar problem and basically those are related to imports, but I haven't been able to solve it in my implementation. Here is my implementation for DialogFragment. import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; public class HotspotScanDialog extends DialogFragment {

Allow outside touch for DialogFragment

久未见 提交于 2019-11-27 15:30:22
I have a Fragment in my app that shows a DialogFragment . I have in the fragment a button that closes the dialog. But when I show the dialogFragment, the touches outside from the dialog do nothing and I can't click the buttons outside from the dialog fragment. How can I allow outside touches for DialogFragment? In order to do that, a flag of the Window that allows the outside touch should be turned on and for the good appearance the background dim flag should be cleared. Since it must be done after dialog is created, I've implemented it via the Handler . @Override public void onViewCreated

DialogFrag#show() from a Fragment throwing “IllegalStateException: Can not perform this action after onSaveInstanceState”

守給你的承諾、 提交于 2019-11-27 14:47:37
问题 Just to be clear, I have read the dozen top SO questions on "IllegalStateException: Can not perform this action after onSaveInstanceState" and I have read Alex Lockwood's blog post on the issue http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html So I'm not asking this blindly. I have a very simple use case case that doesn't involve AsyncTask or any background processing. I have a Fragment that contains a button. On the onClickListener for the button, I

DialogFragment FEATURE_NO_TITLE is shrunk

只谈情不闲聊 提交于 2019-11-27 08:24:43
问题 I'm displaying a DialogFragment . I implemented it with no problems, until I decided to remove the title using getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); .After doing that the whole thing shrinks. Here are my xml and class files. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="@color/white" android:layout_width="match_parent" android:layout_height="match

DialogFragment with clear background (not dimmed)

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:00:23
I'm trying to get the background of a DialogFragment to be completely clear. With setting the style item android:windowIsFloating to true (the default), the DialogFragment displays exactly how I want it to, but has a very dimmed background. By setting android:windowIsFloating to false, I get the clear background I want, but the DialogFragment blows up to about 95% of the screen, leaving only a tiny gap around it where you can see through to the view it overlays. I've tried ton's of tweaks and cannot seem to override this behavior. Do I need to use a PopupWindow to achieve the desired effects,

onRequestPermissionsResult not being called in dialog fragment

隐身守侯 提交于 2019-11-27 06:57:19
I have started to work on Android M runtime permission. Here I am facing the issue that if requestPermissions is called from Dialog Fragment class then onRequestPermissionsResult not getting called in the same Dialog fragment class. But if requestPermissions is called from Activity class or Fragment class then onRequestPermissionsResult method get called in the same class. Here is my sample code: public class ContactPickerDialog extends DialogFragment { private static final int READ_CONTACTS_REQUEST_CODE = 12; private Context mContext; private void loadContact() { if(hasPermission(mContext,

Show dialog from fragment?

有些话、适合烂在心里 提交于 2019-11-27 06:15:03
I have some fragments that need to show a regular dialog. On these dialogs the user can choose a yes/no answer, and then the fragment should behave accordingly. Now, the Fragment class doesn't have an onCreateDialog() method to override, so I guess I have to implement the dialogs outside, in the containing Activity . It's ok, but then the Activity needs to report back the chosen answer somehow to the fragment. I could of course use a callback pattern here, so the fragment registers itself at the Activity with a listener class, and the Activity would report back the answer thru that, or

Android DialogFragment title not showing

坚强是说给别人听的谎言 提交于 2019-11-27 05:41:46
问题 When creating a custom DialogFragment, i set the title using the following: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_dialog_add, container, false); // Setting title here getDialog().setTitle("Add New"); return v; } The above code works fine for me on API level older than 23. For API 23 the title is not showing at all. Any idea why? and how to make the title show on API 23? 回答1: