I am implementing time picker dialog in my android app. I want to set 3 buttons to that dialog, "Set", "Clear", "Cancel".
I am using TimePickerFragment, i have done the code for this but its not working on all android devices correctly, on some devices its work perfect, but on some device its not.
I am using following code:-
public class TimePickerFragment extends DialogFragment implements
OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
min = c.get(Calendar.MINUTE);
final TimePickerDialog timePickerDialog = new TimePickerDialog(
getActivity(), this, hour, min, true);
timePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
getActivity().getResources().getString(R.string.done1),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
isTimeSet = true;
System.out.println("only true");
}
});
timePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
getActivity().getResources().getString(R.string.cancle),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
isTimeSet = false;
System.out.println("only false");
//tvTime1.setText(userAlarmStartTime);
}
});
timePickerDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
getActivity().getResources().getString(R.string.clear),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
isTimeSet = false;
System.out.println("only neutral");
tvTime1.setText("");
}
});
return timePickerDialog;
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
// System.out.println("value in time set:- " + isTimeSet);
if (isTimeSet) {
String userAlarmStartTime;
if (minute < 10) {
userAlarmStartTime = hourOfDay + ":0" + minute;
} else {
userAlarmStartTime = hourOfDay + ":" + minute;
}
tvTime1.setText(userAlarmStartTime);
}
}
}
and for calling this i am using following code:-
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(), "timePicker");
when i debug my code on some devices its not calling onTimeSet()
method, but on some devices its calling that method.
i have searched lot on about this, but i couldn't find anything that will help me to solve problem.
anyone can please tell me where i am going wrong?