I'm currently experiencing some troubles with DialogFragment.
My application look like this :
A MainActivity using ActionBarSherlock to display 6 tabs ( wich all contains a fragment ) On one of those tabs, I show a DialogFragment when the user click a button. This dialog contains some EditText and a button wich save the user input (A postal address) and call a listener in the MainActivity for computing.
My problem is when I turn screen with the dialog up, I managed to make him stay on the screen without losing data but when I call for the listener and then dismiss the dialog, a method is called in the fragment to add the new postal address to a list which is then mapped on a ListView and in this method getActivity() returns null.
I guess the fragment is not yet attached and/or created since my breakpoint in onResume() never break the execution. But i can't see a way to make sure my fragment is created when the listener call for the list update.
I'll be happy to provide further informations if you have any idea that can help me here, Google didn't helped much this time :(
getApplicationContext() error Android Assuming the fragment is attached to an activity so getActivity() will return a non-null object, which is usually true.
Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.
Hey I had the same problem yesterday. Check out this thread for two fixes :
DialogFragment causing nullpointer crash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With