无法从平板电脑上的DatePickerDialog调用onDateSet

时间:2012-09-10 02:15:43

标签: java android tabs galaxy datepickerdialog

我正在使用DatePickerDialog来提示用户输入日期。它在模拟器和我的三星Galaxy Nexus上运行良好,但在我的三星Galaxy Tab 2上没有调用onDateSet。

我注意到,对话框更大,并显示除正常旋转视图之外的日历。这可能是问题吗?

以下是一些代码:

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();
    }
}

是什么导致这个?平板电脑的一个错误?我错过了什么吗?有人能想到一个解决方法吗?

非常感谢!

0 个答案:

没有答案