Search code examples
androidandroid-edittextandroid-timepicker

EditText TimePicker shows KeyBoard


I have an EditText, which should open a TimePicker, but instead of it it opens the keyboard and once I remove the keyboard with the arrow, go back, and the next press shows the TimePicker.

How do I get the TimePicker to display directly without the keyboard?

I leave the xml here:

<com.google.android.material.textfield.TextInputLayout
            style="@style/TextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/fInicio">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/fIni"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="1"
                android:textColor="@color/colorAccent" />
        </com.google.android.material.textfield.TextInputLayout>

and the Java Code:

 fIni.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int anno = calendario.get(Calendar.YEAR);
                int mes = calendario.get(Calendar.MONTH);
                int dia = calendario.get(Calendar.DAY_OF_MONTH);

                final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                        calendario.set(Calendar.YEAR, year);
                        calendario.set(Calendar.MONTH, monthOfYear);
                        calendario.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                        fechaInicio = String.format("%02d/%02d/%04d", dayOfMonth,monthOfYear,year);
                        fIni.setText(fechaInicio);

                        if (!fechaFin.equals(""))
                        {
                            if (testChar(fFin.toString()))
                            {
                                Date fI = ParseFecha(fechaInicio);
                                Date fF = ParseFecha(fechaFin);

                                d=restarFechas(fI,fF);

                                dias.setText(String.valueOf(d));
                            }
                        }


                    }
                };
                new DatePickerDialog(NueAvaCuando.this, date, anno,mes,dia).show();
            }
        });

Solution

  • Add this into EditText

    android:cursorVisible="false"
    android:focusable="false"
    android:inputType="none"
    

    Like that:

    
                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/fIni"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:focusable="false"
                    android:inputType="none"
                    android:maxLines="1"
                    android:textColor="@color/colorAccent" />