Reply to comment

Cancel behavior

I might be missing something but this seems to always persist the value even if you cancel the TimePicker. I changed onTimeChanged to store to a local variable and then did a @Override on onDialogClosed to get the state of the dialog.

If the user said 'ok' then persist the string (In my implementation I didn't make it persist by default, hence the 'isPersistent()'). If the user canceled then I change nothing

	private int mHour = 0, mMinute = 0;
	@Override
	public void onTimeChanged(TimePicker view, int hour, int minute) {
		mHour = hour;
		mMinute = minute;
	}
	@Override
	public void onDialogClosed(boolean positiveResult) {
		if( positiveResult ) {
			if( isPersistent() )
				persistString(mHour + ":" + mMinute);
			mValueText.setText( getNiceTimestring() );
		}
	}

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <strike> <caption>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>.

More information about formatting options