It happens that I have an Edit Text of type textPersonName and when I pass the focus to another Edit Text of type date it shows me the virtual keyboard but I want it not to show it to me, since instead I want a dialog containing a DatePicker (which I already have)
This question has already been asked and the solution I read is:
TuEditText.setInputType(InputType.TYPE_NULL);
and in the xml:
android:inputType="none"
but this only removes the focus and I have to click on the EditText to show the DatePicker dialog and I want it to keep the focus but not show the virtual keyboard and show my DatePicker dialog
Another solution I saw is to remove the focus from the EditText date with the following code:
android:focusable="false"
but this is not what I intend to do since when I remove the focus I must click on the EditText to show the DatePicker dialog I repeat I intend to keep the focus but not show the virtual keyboard and show my DatePicker dialog
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/txt_practica"
android:hint="Practica"
android:layout_marginTop="9dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:hint="Fecha de uso"
android:id="@+id/txt_fechadeuso"
android:layout_below="@+id/txt_practica"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="16dp"
android:onClick="mostrarCalendario" />
</RelativeLayout>
You can try this:
Also try making use of OnFocusChangeListener :
Good morning, by doing
focusable=false
you have the onTouchListener to open the DatePicker, if you still need to click you can do this:What I usually do in these cases is to make a fake editText, basically it is a textView with a customized linearLayout in the background to make it look like an editText, since customizing a pre-lollipop TextView can cause problems.
Finally I leave you a simple way to hide the keyboard:
All the best
What you are looking for is to disable the android virtual keyboard and we must do the following for that: 1.- We must go to the AndroidManifest.xml. 2.- In it we must add the following:
3.- After that we clean the android solution and with that when the user selects the edittext the android virtual keyboard will be hidden.
friend try to put the following attribute android:windowSoftInputMode="stateHidden" in the manifest:
You just have to put in the attributes(XML.) of the Edittext:
With focusable set to "false" it will be prevented from being typed on, therefore the keyboard will not appear, and with clickable set to "true" it will be clickable, therefore the calendar will appear.