Activity cannot be cast to android.app.DatePickerDialog$OnDateSetListener -


public class datepickerdialogfragment extends dialogfragment {     private context context;      public datepickerdialogfragment(context context) {         this.context = context;     }      public dialog oncreatedialog(bundle savedinstancestate) {         final calendar c = calendar.getinstance();         return new datepickerdialog(context, (ondatesetlistener) context,                 c.get(calendar.year), c.get(calendar.month),                 c.get(calendar.day_of_month));     } }      public class mactivity extends sherlockfragmentactivity implements             ondatesetlistener {         datefield.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             android.support.v4.app.fragmentmanager fm = getsupportfragmentmanager();             dialogfragment newfragment = new datepickerdialogfragment(mactivity.this);             newfragment.show(fm, "date_frag");         }     });     } 

unable cast context(of activity impletements ondatechangedlistener) ondatesetlistener.

just try working code.

public static class datepickerfragment extends dialogfragment implements             datepickerdialog.ondatesetlistener {     private int year, month, day;     private button btn;      @override     public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) {          this.year = year;         this.month = monthofyear;         this.day = dayofmonth;      }      public void setobject(button v) {         this.btn = v;     }      @override     public dialog oncreatedialog(bundle savedinstancestate) {          // use current date default date in picker         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);          // create new instance of datepickerdialog , return         return new datepickerdialog(getactivity(), this, year, month, day);     } }  public class submitpost extends sherlockfragmentactivity { datefield.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             datepickerfragment newfragment = new datepickerfragment();             newfragment.setobject(v);             newfragment.show(getsupportfragmentmanager(), "datepicker");        }     }); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -