当前位置: 网学 > 编程文档 > Android > 正文

TimePicker Preference 时间选择 实现

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/19
下载{$ArticleTitle}原创论文样式

 public class PrefAutoRefreshStartTime extends DialogPreference implements TimePicker.OnTimeChangedListener {

  /** * The validation expression for this preference */  private static final String VALIDATION_EXPRESSION = "[0-2]*[0-9]:[0-5]*[0-9]";   /** * The default value for this preference */  private String defaultValue;   /** * @param context * @param attrs */  public PrefAutoRefreshStartTime(Context context, AttributeSet attrs) {super(context, attrs);initialize(context); } /** * @param context * @param attrs * @param defStyle */public PrefAutoRefreshStartTime(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);initialize(context); } /** * Initialize this preference */private void initialize(Context context) {setPersistent(true);SharedPreferences sp = getPreferenceManager().getDefaultSharedPreferences(getContext());String timeTemp = sp.getString(IConfigsParameters.KEY_P_AUTOFRESH_START, "");if(null != timeTemp){setSummary(packageTimeInfo(timeTemp)); }else{setSummary(packageTimeInfo(context.getText(R.string.time_default_auto_update_start).toString())); } } /* * (non-Javadoc) * * @see android.preference.DialogPreference#onCreateDialogView() */@Override protected View onCreateDialogView() {TimePicker tp = new TimePicker(getContext());tp.setOnTimeChangedListener(this); /** */SharedPreferences sp = getPreferenceManager().getDefaultSharedPreferences(getContext());String timeTemp = sp.getString("p_autofresh_strart", "");String time = timeTemp.split(":");if((time != null) && (time.length == 2)){Integer hour = Integer.decode(time[0]);Integer min = Integer.decode(time);tp.setCurrentHour(hour);tp.setCurrentMinute(min); }else{ /** */int h = getHour();int m = getMinute();if (h >= 0 && m >= 0) {tp.setCurrentHour(h);tp.setCurrentMinute(m); } } return tp; } /* * (non-Javadoc) * * @see * android.widget.TimePicker.OnTimeChangedListener#onTimeChanged(android * .widget.TimePicker, int, int) */@Override public void onTimeChanged(TimePicker view, int hour, int minute) {setSummary(packageTimeInfo((""+hour+":"+minute)));persistString(hour + ":" + minute); } /* * (non-Javadoc) * * @see android.preference.Preference#setDefaultValue(java.lang.Object) */@Override public void setDefaultValue(Object defaultValue) {// BUG this method is never called if you use the ''android:defaultValue'' // attribute in your XML preference file, not sure why it isn''t super.setDefaultValue(defaultValue);if (!(defaultValue instanceof String)) {return; } if (!((String) defaultValue).matches(VALIDATION_EXPRESSION)) {return; } this.defaultValue = (String) defaultValue; } /** * Get the hour value (in 24 hour time) * * @return The hour value, will be 0 to 23 (inclusive) */private int get

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号