I am trying to launch a timepicker from a button in a fragment
I\'ve read post regarding the same problems about the Error but the codes doesn\'t match
About the
MainActivity cannot be cast to android.app.TimePickerDialog$OnTimeSetListener
it is happening because you are trying to cast your activity to OnTimeSetListener
return new TimePickerDialog(getActivity(),(TimePickerDialog.OnTimeSetListener) getActivity(), cHour, cMinute, android.text.format.DateFormat.is24HourFormat(getActivity()));
Make sure that your activity is extending the OnTimeSetListener, and if it so, you may try to convert right to your activity
return new TimePickerDialog(getActivity(),(MainActivity) getActivity(), cHour, cMinute, android.text.format.DateFormat.is24HourFormat(getActivity()));
because your activity will be a instance of OnTimeSetListener.
Also, I do not recommend using the getActivity() to get the listener from your fragment, its better if you have your listener not attached to your activity.