Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should use <strong>TimePicker.OnTimeChangedListener</strong> to handle <strong>onTimeChanged</strong> action if the user has changed hours or minutes values by tapping on plus or minus, or by editting the time manualy using keyboard.</p> <p>And this is <strong>my code</strong>:</p> <p>Activity:</p> <pre><code>public class MainActivity extends Activity implements TimePicker.OnTimeChangedListener { private TextView resultTime; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); resultTime = (TextView) findViewById(R.id.activity_main_textview_resulttime); TimePicker timePicker = (TimePicker) findViewById(R.id.activity_main_timepicker); { timePicker.setIs24HourView(true); timePicker.setOnTimeChangedListener(this); } } @Override public void onTimeChanged(TimePicker timePickerView, int hours, int minutes) { final String stringNewTime = hours + " : " + minutes; resultTime.setText(stringNewTime); } } </code></pre> <p>Layout:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" &gt; &lt;TimePicker android:id="@+id/activity_main_timepicker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="14dip" android:layout_marginRight="16dip" android:focusable="true" android:focusableInTouchMode="true" /&gt; &lt;TextView android:id="@+id/activity_main_textview_resulttime" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Hope, it will help you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload