Code example for TimePicker

Methods: setCurrentHoursetCurrentMinutesetIs24HourViewsetOnTimeChangedListener

0
	public View onCreateDialogView()
	{ 
		settings = PreferenceManager.getDefaultSharedPreferences(context);
		 
		LinearLayout dialogLayout = new LinearLayout(context);
		timePicker = new TimePicker(context);
		timePicker.setIs24HourView(true);
		timePicker.setOnTimeChangedListener(new OnTimeChangedListener(){
 
			@Override 
			public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
				 
				if (arg1 > 14)
				{ 
					arg0.setCurrentHour(0); // TODO
				} 
			} 
		}); 
		 
		if (settings.getString("pref_displayTime", "unset") == "unset")
		{ 
			Editor editor = settings.edit();
			editor.putString("pref_displayTime", "6:00");
			editor.commit();
			timePicker.setCurrentHour(6);
			timePicker.setCurrentMinute(0);
		} 
		else  
		{ 
			String savedTime = settings.getString("pref_displayTime", "6:00");
			timePicker.setCurrentHour(Integer.valueOf(savedTime.substring(0,savedTime.indexOf(":"))));
			timePicker.setCurrentMinute(Integer.valueOf(savedTime.substring(savedTime.indexOf(":") + 1,savedTime.length())));
		} 
		 
		dialogLayout.addView(timePicker);
		return dialogLayout;	
	} 
Connect your IDE to all the code out there  Get Codota for Java