android-dialogfragment

Using getFragmentManager() vs getSupportFragmentManager()?

不羁的心 提交于 2019-11-26 20:24:27
问题 When should I use getFragmentManager() when showing DialogFragments, and when should I use getSupportFragmentManager()? Currently, I am showing my DialogFragments as follows: myDialogFragment.show(getFragmentManager(), "My Dialog Fragment"); 回答1: If you are using API >= 14, then use getFragmentManager() and while using Support Package you have to use getSupportFragmentManager() For Example Android Support Package v4 or v13. 回答2: When you are using android.support.v4.app.FragmentManager then

DialogFragment and onDismiss

霸气de小男生 提交于 2019-11-26 20:15:37
I am using a DialogFragment , which I am showing like this from an Activity : DialogFragmentImage dialog = DialogFragmentImage.newInstance(createBitmap()); dialog.onDismiss(dialog);.onDismiss(this); dialog.show(getFragmentManager(), "DialogFragmentImage"); I would like to check when the DialogFragment was dismissed (for example when the back button was pressed), but in my Activity . How can I do that? How can I "tell" my activity that the DialogFragment has been dismissed? Yaroslav Mytkalyk Make your Activity implement OnDismissListener public final class YourActivity extends Activity

Why is Android O failing with “does not belong to this FragmentManager!”

有些话、适合烂在心里 提交于 2019-11-26 19:51:26
问题 I have migrated my application to Android O in Android Studio 3 Running on an Android O emulator all my dialogFragments now fail with :- java.lang.IllegalStateException: Fragment MyDialogFragment{43ccf50 #2 MyDialogFragment} declared target fragment SettingsFragment{ceed549 #0 id=0x7f0f0142 android:switcher:2131689794:0} that does not belong to this FragmentManager! at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1316) at android.support.v4.app

DialogFragment fullscreen shows padding on sides

好久不见. 提交于 2019-11-26 19:43:06
问题 I am creating a custom DialogFragment that is displayed underneath the actionbar. So far everything works great. The layout parameters for dialog fragment are match_parent for width and wrap_content for height. I have tried every solution including setting the layout parameters .width and by getting Display size and removing the themes. However no matter what there is a small amount of space on left, right and top side of the dialog that is invisible. I need to know how to remove this space

How to set DialogFragment's width and height?

这一生的挚爱 提交于 2019-11-26 18:05:56
I specify the layout of my DialogFragment in an xml layout file (let's call it layout_mydialogfragment.xml ), and its layout_width and layout_height attributes particularly (to be 100dp each let's say). I then inflate this layout in my DialogFragment's onCreateView(...) method as follows: View view = inflater.inflate(R.layout.layout_mydialogfragment, container, false); Unfortunately, I find that when my dialog (DialogFragment) appears, it does not respect the layout_width and layout_height specified in its xml layout file (and my dialog shrinks or expands variably depending on content). Anyone

ActionBar in a DialogFragment

坚强是说给别人听的谎言 提交于 2019-11-26 18:05:40
In the Calendar app on my Galaxy Tab 10.1, when creating a new event a dialog comes up with Done and Cancel buttons in the title bar/action bar area. I'd like to implement this in my app. I've tried using setHasOptionsMenu(true) in addition to overriding onCreateOptionsMenu in my DialogFragment subclass, but my action items do not appear. I've also tried calling getDialog().getActionBar() from within onCreateView but it always returns null . I am able to get this working if I start an Activity rather than showing a dialog but that takes up the whole screen. Is there a standard way to do this

Fragment must be a public static class to be properly recreated from instance state

ぐ巨炮叔叔 提交于 2019-11-26 17:48:59
问题 After updating to the latest support repository, compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:design:24.2.0' compile 'com.android.support:percent:24.2.0' compile 'com.android.support:recyclerview-v7:24.2.0' I'm getting the weird exception. java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) at android.support.v4

onRequestPermissionsResult not being called in dialog fragment

丶灬走出姿态 提交于 2019-11-26 17:36:24
问题 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

passing argument to DialogFragment

蹲街弑〆低调 提交于 2019-11-26 17:14:12
I need to pass some variables to DialogFragment , so I can perform an action. Eclipse suggests that I should use Fragment#setArguments(Bundle) But I don't know how to use this function. How can I use it to pass variables to my dialog? JafarKhQ Using newInstance public static MyDialogFragment newInstance(int num) { MyDialogFragment f = new MyDialogFragment(); // Supply num input as an argument. Bundle args = new Bundle(); args.putInt("num", num); f.setArguments(args); return f; } And get the Args like this @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Full Screen DialogFragment in Android

爱⌒轻易说出口 提交于 2019-11-26 15:41:15
I'm trying to show an almost fullscreen DialogFragment. But I'm somehow not able to do so. The way I am showing the Fragment is straight from the android developer documentation FragmentManager f = ((Activity)getContext()).getFragmentManager(); FragmentTransaction ft = f.beginTransaction(); Fragment prev = f.findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); // Create and show the dialog. DialogFragment newFragment = new DetailsDialogFragment(); newFragment.show(ft, "dialog"); I know naively tried to set the RelativeLayout in the fragment to fill