Create A Datepicker And Timepicker In The Tab Fragment Error
Solution 1:
At first rectify your onCreateView
method .
@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
contentView=inflater.inflate(R.layout.daily_weight_fragement, container, false);
btnTime = (EditText) contentView.findViewById(R.id.time_field);
btnTime.setOnClickListener(this);
btnDate = (EditText) contentView.findViewById(R.id.date_field);
btnDate.setOnClickListener(this);
return contentView;
}
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
Logcat Returns
Error:(79, 35) error: no suitable constructor found for DatePickerDialog(KeyInWeightF,,int,int,int) constructor DatePickerDialog.DatePickerDialog(Context,int,OnDateSetListener,int,int,int) is not applicable (actual and formal argument lists differ in length) constructor DatePickerDialog.DatePickerDialog(Context,OnDateSetListener,int,int,int) is not applicable (actual argument KeyInWeightF cannot be converted to Context by method invocation conversion)
Solutions
You should usegetActivity()
instead of KeyInWeightF.this
getActivity() in a Fragment returns the Activity the Fragment is currently associated with.
timePickerDialog = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
As same as
Stringtimestring= DateUtils.formatDateTime(getActivity(),timeCalendar.getTimeInMillis(),DateUtils.FORMAT_SHOW_TIME);
Solution 2:
To create a Date and time picker in your tab fragment you can take reference from this
and even this is helpful .
Solution 3:
You should use getActivity()
instead of SomeActiviyy.this
datePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener()
Post a Comment for "Create A Datepicker And Timepicker In The Tab Fragment Error"