I'm getting a problem in a UI form that I'm building in Android. In that form I have some edit text in which the user has to touch them to open a dialog fragment. In the dialog fragment, user can set a value and then, this value is shown on the edittext touched. The problem is the following: when user close the dialog fragment and the edittext touched gets focus, if the user press the back button to go out, the onBackPressed() method is not being called.
I must clarify that the edittexts that open a dialog fragment doesn't show keyboard because the user can't write on them. I don't want to use textviews.
Here I show you part of the layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_input_when"
android:layout_marginTop="30dp">
<EditText
android:hint="@string/meeting_when"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text_when"
android:textSize="18sp"
android:inputType="text|date"
android:textIsSelectable="true"
android:focusable="true"
android:drawableLeft="@drawable/ic_black_18dp"
android:drawableStart="@drawable/ic_black_18dp"
android:drawablePadding="10dp"
android:onClick="onEditTextWhenClicked"
android:nextFocusForward="@+id/edit_text_time"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/text_input_time"
android:layout_marginTop="30dp">
<EditText
android:hint="@string/meeting_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text_time"
android:textSize="18sp"
android:inputType="time"
android:textIsSelectable="true"
android:nextFocusForward="@+id/edit_text_place"
android:focusable="true"
android:drawableLeft="@drawable/ic__black_18dp"
android:drawableStart="@drawable/ic__black_18dp"
android:drawablePadding="10dp"
android:onClick="onEditTextTimeClicked" />
</android.support.design.widget.TextInputLayout>
....
....
</LinearLayout>
So, for example, if the user touch the "when" edit text, a datepicker dialog is open:
when the user set the date, the dialog fragment is closed and the value is setted on the edit text
And now, if the user press the back button, it doesn't work.
In the activity I have
@Override
public void onBackPressed(){
if ( !areAllFieldEmpty() ) {
showAlertCloseDialog();
}else
super.onBackPressed();
}
But these method it doesn't be called. . I don't have any idea about how to solve it. Please help me. If you need more information, let me know it. Thanks.