Jump to content
Android Forum - A Community For Android Users and Enthusiasts

Recommended Posts

Hi All!


I've a problem with a DatePickerDialog following steps from Android Tutorial.


Linking a TextView to launch a DatePickerDialog when gets focused as you can see below:


   	 EditText fNac = (EditText)findViewById(R.id.regFecha);
       fNac.setonfocusChangeListener(new View.onfocusChangeListener(){

           public void onfocusChange(View v, boolean hasFocus) {
               // TODO Auto-generated method stub
               // Desde aquí lanzamos el datepicker
               if (hasFocus){
                   DialogFragment newFragment = new DatePickerFragment();
                   newFragment.show(getSupportFragmentManager() , "datePicker");


Works fine, the DatePickerDialog is launched. I instance a new DatePickerFragment class that is created in this way:


import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.widget.DatePicker;

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

   private DatePickerDialog mDatePickerDialog;

   public Dialog onCreateDialog(Bundle savedInstanceState){
       // Usamos la fecha actual como primera fecha a mostrar
       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);

       // Devolvemos la instancia de un Dialog con la fecha actual
       mDatePickerDialog = new DatePickerDialog(getActivity(),this,year,month,day);
       return mDatePickerDialog;

   public void onDateSet(DatePicker view, int year, int month, int day) {
       // TODO Auto-generated method stub

   public void onDateChanged(DatePicker view, int year, int monthOfYear,
           int dayOfMonth) {
       // TODO Auto-generated method stub
       Log.v("LOG_CAT", "Ok2");


And here is the problem. I want to change Dialog's title using onDateChanged method, but it's never called. I tried to create a onDateChangedListener but DatePickerDialog doesn't have one.


How can i do this?


Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...