onDateSet does not get called from DatePickerDialog on tablet
Posted
by
cit
on Stack Overflow
See other posts from Stack Overflow
or by cit
Published on 2012-09-10T02:15:42Z
Indexed on
2012/09/10
3:38 UTC
Read the original article
Hit count: 123
I am using a DatePickerDialog to prompt the user for a date. It works fine in the simulator and on my Samsung Galaxy Nexus, but onDateSet does not get called on my Samsung Galaxy Tab 2.
I noticed, that the dialog is bigger and shows a calendar besides the normal spin view. Can that be the problem?
Here is some code:
import java.util.Calendar;
import java.util.Date;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
import com.cbit.gtbetapp.R;
import com.cbit.gtbetapp.gui.racedata.MeetingDataActivity;
import com.cbit.gtbetapp.gui.racedata.MeetingListFragment;
import com.cbit.gtbetapp.logic.Utility;
public class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
protected Date date = null;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Utility.getToday();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
date = c.getTime();
// Create a new instance of DatePickerDialog and return it
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day) {
@Override
public void onDateChanged(DatePicker view, int year, int month, int day) {
super.onDateChanged(view, year, month, day);
setTitle(getString(R.string.date_picker_title));
}
};
dialog.setTitle(getString(R.string.date_picker_title));
dialog.setButton(DatePickerDialog.BUTTON_POSITIVE,
getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Intent intent = new Intent(getActivity(), MeetingDataActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(MeetingListFragment.EXTRA_DATE, date.getTime());
startActivity(intent);
}
});
dialog.setButton(DatePickerDialog.BUTTON_NEGATIVE,
getString(R.string.button_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
return dialog;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
date = c.getTime();
}
}
What could cause this? A bug in the tablet? Am I missing something? Can anyone think of a workaround?
Thanks a lot!
© Stack Overflow or respective owner