我有一个自定义 DialogPreference。从 PreferenceScreen 调用 Dialog。一切正常,对话框启动并显示 TimePicker。
但是如何获得选定的值?首先,我尝试将选定的时间写在偏好的摘要中。(因此 var xxx :) 稍后,我想将值保存在 SharedPreferences 中。
这就是我现在所拥有的:
public class Calendar extends DialogPreference implements
TimePicker.OnTimeChangedListener {
TimePicker tp;
int xxx;
public Calendar(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public Calendar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize();
}
private void initialize() {
setPersistent(true);
}
@Override
protected View onCreateDialogView() {
tp = new TimePicker(getContext());
tp.setIs24HourView(true);
return tp;
}
@Override
public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
}
@Override
public void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
// getEditor().
setTitle(getTitle());
setSummary(Integer.toString(xxx));
}
}
private TimePicker.OnTimeChangedListener mTimeSetListener =
new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
xxx=hourOfDay;
}
};
}
非常感谢和最好的问候