Q:

How to setText from a DialogFragment with DatePickerDialog

I'm building an app where you can choose a date with a DatePickerDialog, after you select and tap in "Ok", the date you choose must be shown in a TextView. 
I'm having problems doing that since i can't just use "setText.mTexView(foo)" inside a DialogFragment... I've tried passing the textview through the constructor or getting the tv in the fragment but i couldn't, help please. 
This is my code:
public class PickDate_main extends AppCompatActivity {

EditText tv_fecha;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickdate_main);
}

public void showDatePickerDialog(View v){//This method is executed from the layout with a button

    PickDate_Dialog dialog = new PickDate_Dialog();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    dialog.show(ft, "Date pickeerr");
}
}

--
public class PickDate_Dialog extends DialogFragment implements DatePickerDialog.OnDateSetListener{

public PickDate_Dialog(){
}

public Dialog onCreateDialog(Bundle savedInstanceState){

    final Calendar c= Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    return new PickDate_Dialog(getActivity(),this,year,month,day);
}

@Override
public void onDateSet(DatePicker view, int year, int month, int day) {

    String date = day + "-"+(month+1)+"-"+year;

    //I want to write the string "data", i suppose it must be here
}

}

A:

I believe it should work if you send the textview to PickDate_Dialog, save it, and call it when necessary. Not sure about return new PickDate_Dialog(getActivity(),this,year,month,day); though.
public class PickDate_Dialog extends DialogFragment implements DatePickerDialog.OnDateSetListener{

    private EditText dateEditText;

    public PickDate_Dialog(EditText et){
        dateEditText = et;
    }

    public Dialog onCreateDialog(Bundle savedInstanceState){

        final Calendar c= Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        //Do you have a constructor for this? This is likely your issue

        return new PickDate_Dialog(getActivity(),this,year,month,day);
    }

    @Override
    public void onDateSet(DatePicker view, int year, int month, int day) {

        String date = day + "-"+(month+1)+"-"+year;
        if (dateEditText != null)
            dateEditText.setText(date);
    }

}

However, here are a few more ideas:
Option 1: Have a look at interfaces. It's a way to allow you to send callbacks between classes (DatePickerDialog.OnDateSetListener is an example). Create a new interface in your Dialog class
public interface PickDateInterface {
    void onDateSet(String date)
}

create a variable for it
private PickDateInterface mPDInterface;
and add it to the original onDateSet
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
    String date = day + "-"+(month+1)+"-"+year;

    if (mPDInterface != null) {
        mPDInterface.onDateSet(date);
    }
}

and when you create the dialog, just add this interface as a parameter, and add what you need to do in the interface.
 
Option 2:
create a public method in your activity and call it via
(([Your activity name])[your context]).your method;
You're basically casting your context to your activity and using the method
Example:
((PickDate_main).getContext()).setDateText(date);

