I have fragment1 and DatePickerFragment
In case DatePickerFragment extends DialogFragment
I would like when selecting the date to return to the fragment.
But you're giving it here:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Fragment.onActivityResult(int, int, android.content.Intent)' on a null object reference
The recovery method is this:
No DatePickerFragment extends DialogFragment
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
//...
SimpleDateFormat data_br = new SimpleDateFormat( "dd/MM/yyyy" );
String data = data_br.format( date );
Intent i = new Intent();
i.putExtra( "selectedDate",data );
getTargetFragment().onActivityResult( getTargetRequestCode(), 2, i );
}
And no onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("RequestCode",""+requestCode);
if( requestCode == 1 ){
}
}
How do I return the selected value in the DialogFragment for the snippet?