1
I have following XML:
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_weight="6"
android:maxLength="10"
android:textColorHint="#FFF8E1"
android:theme="@style/StyledTilEditText">
<android.support.design.widget.TextInputEditText
android:id="@+id/edt_DtNasc"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:clickable="true"
android:fontFamily="sans-serif-condensed"
android:hint="Data Nascimento"
android:text="dd/MM/AAAA"
android:inputType="date"
android:maxLength="10"
android:maxLines="1"
android:singleLine="true"
android:textColor="#D3D3D3"
android:textSize="13dp" />
</android.support.design.widget.TextInputLayout>
I would like, when clicking on this item, the keyboard to hide or the dateTimePicker to appear, but to do so, I have to click 2x on the item. I made the following code, but it didn’t work:
edt_dtnasc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt_dtnasc.setInputType(InputType.TYPE_NULL);
hideSoftKeyboard(getActivity());
dateTimePicker();
}
});
hideSoftKeyboard:
public void hideSoftKeyboard(Activity activity) {
try {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View currentFocus = activity.getCurrentFocus();
if (currentFocus != null) {
inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Datetime:
private void dateTimePicker() {
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date_time = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year;
edt_dtnasc.setText(date_time);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
excellent!!!!!!!!
– Henrique