1

我正在使用警报应用程序,我想显示一个带有两个按钮(确定和取消)的 TimePickerDialog 我使用此代码在使用单击确定按钮时获取当前时间:

显示对话框的代码:

    final TimePickerDialog pic = new TimePickerDialog(
        TimerSettingsActivity.this,
        android.R.style.Theme_Holo_Dialog_NoActionBar,
        timePickerCallback, hour, minute, true);
pic.setTitle(getResources().getString(R.string.dialog_time_title));
pic.setButton(DatePickerDialog.BUTTON_POSITIVE, "OK",
        new DatePickerDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_POSITIVE)
                    mIsClickOkButton = true;
            }
        });
pic.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Cancel",
        new DatePickerDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == DialogInterface.BUTTON_NEGATIVE) {
                    mIsClickOkButton = false;
                }
            }
        });
pic.setOnDismissListener(new OnDismissListener() {

    @Override
    public void onDismiss(DialogInterface dialog) {
    }
});
pic.show();

这是设置时间监听器:

OnTimeSetListener timePickerCallback = new OnTimeSetListener() {

    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        if (mIsClickOkButton) {
            // Save time to pref
            String pref_time = String.valueOf(hourOfDay) + ","
                    + String.valueOf(minute);
            mEditor.putString(Common.PREFS_TIME, pref_time);
            mEditor.commit();
            mTxtTime.setText(Common.createTimeStringToShow(hourOfDay,
                    minute));
        }
    }
};

我使用 LG Optimus G 进行测试,运行正常,此关闭的行为是 OK 按钮按下 => onTimeSet

但是当我为我的客户(三星设备)发布这个应用程序时,当按下 OK 按钮时,它无法正常运行。有任何想法吗?

谢谢!

4

0 回答 0