android - Updating parent Fragment from DialogFragment raises NullPointerException -


I try to update from section with a DialogFragment piece program is added to a activity . Picks up a NullPointerException while clicking on the positive button in the dialog, because the parent section was not found. (I do not use SupportFragments .)

Any suggestions?

Parent Activity :

  extends the results of the public category activity {@ Override Protected Zero (Creates Bundle Instantstate) {Super.onCreate (savedInstanceState); If (savedinstancestate == empty) {getFragmentManager () BeginTransaction (). Add (RID. Activism_Demographics, ResultDetailsOneFragment.newInstance ()). Commit (); Layout of 'ResultActivity':  
  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; ; & Lt; FrameLayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" Android: id = "@ + id / Activity_result" Tools: Reference = "com.myApp.view.ResultActivity" tool: ignore = "mergeurfrem" />  

Layout of 'ResultDetailsOneFragment':

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" Android: id = "@ + id / Fragment_result_details_one" Tool: Reference = "com.myApp.view.ResultActivity $ ResultDetailsOneFragment" & gt; & Lt ;! - ... - & gt; & Lt; / RelativeLayout & gt;  

Interface for callback:

  Public interface EditResultDialogListener {void onDialogFinish (); }  

Dialogfrugment :

  Edit public category: The writing dialog dialog dialog extension {@Override protected void onDialogPositiveButtonClick (DialogInterface dialog, int ) {EditResultDialogListener ResultsWatching Splitter = (Editorial Dialoglaster) getFragmentManager (). FindFragmentById (R.id.fragment_result_details_one); / * Here is NullPointerException * / resultDetailsOneFragment.onDialogFinish (); }}  

You are receiving the nullpointer exception because you find this piece inside Attempting the fragment dialogue

What do you have to do ->

Set the target piece when showing the dialog ...

  dialogFragment.setTargetFragment (The resulting description. DialogFragment.show (GetFragmentManager (), "Tag");  

Then in your onDialogPositiveClick,

  @Orride Safe void onDialogPositiveButtonClick (DialogInterface dialog, int, which) { // Send the event back to the original piece getTargetFragment () .onActivityResult (MY_REQUEST_CODE, activity. RESULT_OK, tap);}  

Then click the positive button on the dialog, the on-activate result of your piece To be called Ga. Make sure you override the on-Aktivetiv result in your pieces class.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -