---
title: "TimePicker in Andriod"  
description: "1.	Time Picker is a control which provides user to pick the time from the analog clock to pick the time.     2.	It allows to pick hours first and then"  
author: "Nitish Kesarwani"  
published: 2017-12-28  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/12749/timepicker-in-andriod  
category: "android apps"  
tags: ["android", "java", "time", "datetime"]  
reading_time: 3 minutes  

---

# TimePicker in Andriod

###### Time Picker

1. Time Picker is a [control](https://yourviews.mindstick.com/view/83439/bipartisan-gun-control-bill-passed-in-us-after-decades) which provides user to pick the time from the analog clock to pick the time.

2. It allows to pick hours first and then minutes.

3. It is a part of widget control panel.

4. It provides two formats one is 24 hours and another one is AM/PM.

5. TimePicker, [TextView](https://www.mindstick.com/forum/23237/how-do-i-center-text-horizontally-and-vertically-in-a-textview-in-android) and Button [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) are used in this program.

6. [onClickListener](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach)() and timePicker() method is used to invoke method.

##### Attributes

• **[android](https://www.mindstick.com/articles/1567/navigation-drawer-implementation-in-android): timePickerMode:** The default value of timePicker is a clock(1) and it can set as a spinner mode.

##### Methods

**• is24HourView():** This method checks whether a 24-hour view is true or false

**• setis24HourView():** By this method, we can set 24-hour view status

**• isEnabled():** By this method, we get the enabled status of view

**• setEnabled():** This method is used to enable the view status

**• setCurrentHour():** It receives the current status of an hour clock from the user

**• setCurrentMinutes():** It sets the current status of minutes from clock by a user

**• setonTimeChangedListener():** This method generates a [response](https://yourviews.mindstick.com/view/86896/biden-s-assertive-response-to-special-counsel-critique-on-memory-strength) when the user selects the value from the clock

\

###### Android_manifest.xml

```
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapsample.msclient009.timepicker">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
```

###### Activity_Main.xml

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mapsample.msclient009.timepicker.MainActivity">
    <TimePicker
        android:id="@+id/tpick"
        android:layout_width="370dp"
        android:layout_height="150dp"
        android:layout_weight="1" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <Button
         android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="timePicker Clock" />
        <TextView
            android:id="@+id/tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#199119"/>
    </LinearLayout>
</LinearLayout>
```

###### Main_Activity.java

```
package com.mapsample.msclient009.timepicker;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {
TimePicker tp;
TextView tv;
Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main );
        tp =(TimePicker)findViewById (R.id.tpick );
        tv = (TextView)findViewById ( R.id.tv );
        btn =(Button)findViewById ( R.id.btn );
        tv.setText(timePicker ());
        btn.setOnClickListener ( new View.OnClickListener ( ) {
            @Override
            public void onClick(View v) {
                tv.setText ( timePicker () );
            }
        } );

    }
    public String timePicker()
    { String time = "Current Time :"+tp.getCurrentHour ()+":"+tp.getCurrentMinute ();
    return time;
    }
}
```

\

##### Run Your APP

![TimePicker in Andriod](https://www.mindstick.com/mindstickarticle/3ba16952-6ba2-4347-ac85-eae1c26fcba5/images/da8d7287-a651-49d0-879c-64b1e9289a75.png) ![TimePicker in Andriod](https://www.mindstick.com/mindstickarticle/3ba16952-6ba2-4347-ac85-eae1c26fcba5/images/b6939f65-c5dc-4add-8d54-84b83ef4701a.png)\

---

Original Source: https://www.mindstick.com/articles/12749/timepicker-in-andriod

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
