Restrict input to date only in Android EditText

  • Replies:4
  • Answered
Suresh Kumar
  • Forum posts: 9

Sep 11, 2018, 7:49:04 PM via Website

I would like the user to input date only in my Android app EditText. I am opening the calendar when the user focus on the EditText control. But sometimes the built-in keyboard appears on focussing instead of calendar. How can I restrict date only here? Here is my EditText in activity_main.

 <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:id="@+id/tEndDate"

    android:layout_marginBottom="2dip" android:textAlignment="textEnd"/>
Reply
Best answer
James Watson
  • Forum posts: 1,583

Sep 12, 2018, 7:44:42 AM via Website

android:inputType="date"

Or try another date picker control.

Download size < 0.15 MB. But also accurate enough, ad-free & free.
The minimalist app available on Play Store: https://goo.gl/ws42fN
Blog: https://okblackcafe.blogspot.com Your 5-star is appreciated.

Helpful?
Suresh Kumar
Reply
Suresh Kumar
  • Forum posts: 9

Sep 13, 2018, 8:47:50 PM via Website

Thanks a lot James. That worked !!! I have really started liking Android development !!! Cool..

Helpful?
Reply
James Watson
  • Forum posts: 1,583

Sep 14, 2018, 1:24:58 AM via Website

You are welcome Suresh. :D Would you like to support a 5-star for my free app as mentioned in my forum signature. Thanks in advance. (smug):D

— modified on Sep 15, 2018, 3:58:50 AM

Download size < 0.15 MB. But also accurate enough, ad-free & free.
The minimalist app available on Play Store: https://goo.gl/ws42fN
Blog: https://okblackcafe.blogspot.com Your 5-star is appreciated.

Helpful?
Reply
mansi suchak
  • Forum posts: 1

Jun 24, 2021, 7:25:46 PM via Website

what is coding in kotlin used to get year from edittext with input type date.

Helpful?
Reply