在編輯完成後,我有一個android對話框中的EditText(searcField),並關閉對話框。在android對話框中的clearFocus不起作用
然後我去其他EditText,焦點仍然在searchField。
有什麼想法?
感謝
編輯: 有太多在這裏發帖,希望這能幫助有點明白了我的問題。
顧客對話視圖
<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代碼
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;
}
}
,你說的重點是未顯示的對話框的領域?你怎麼知道它是重點? – invertigo
是的,你是對的,焦點仍然在對話的領域。我用addTextChangedListener註冊了所有的textField。然後在afterTextChanged回調中,我檢查是否(searchField.hasFocus()),它總是如此。 – triston
也許發佈一些代碼,所以我們可以更好地看到發生了什麼 – invertigo