I have a EditText(searcField) in a android dialog, after I finished the editing, and dismiss the dialog.
then i go to other EditText, the focus is still in searchField.
Any idea?
thanks
EDIT: there are too much to post in here, hope this can help a bit to understand my issue.
Customer dialog view
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:orientation="horizontal" >
<EditText
android:id="@+id/search_field"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="left"
android:inputType="textNoSuggestions|textVisiblePassword"
android:layout_weight="0.70"
android:hint="type item name to search"/>
</LinearLayout>
<ListView
android:id="@+id/itemList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#00000000"
android:descendantFocusability="beforeDescendants"
android:scrollbars="none"/>
</LinearLayout>
Java code
View searchView = getActivity().getLayoutInflater().inflate(R.layout.search, null, false);
EditText searchField = (EditText)productEditView.findViewById(R.id.search_field);
searchField.addTextChangedListener(this);
...
public void afterTextChanged(Editable text) {
if (searchField.hasFocus()) {
Log.i("MyApp", "searchField is still focused");
return;
}
if (otherField.hasFocus()){
Log.i("MyApp", "other field");
return;
}
}
Another, albeit somewhat hacky, solution I regularly use is setting android:focusable="true"
and android:focusableInTouchMode="true"
to the parent view (LinearLayout, RelativeLayout, etc) of a layout if I want to be able to clearFocus() of an EditText, or open the Activity/Fragment without the first EditText from being focused automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With