gpt4 book ai didi

android - android 对话框中的 clearFocus 不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 08:03:29 25 4
gpt4 key购买 nike

我在 android 对话框中有一个 EditText(searcField),在我完成编辑后关闭对话框。

然后我转到其他EditText,焦点还在searchField。

有什么想法吗?

谢谢

编辑:这里有太多要发布的内容,希望这对理解我的问题有所帮助。

客户对话 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代码

    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;
}
}

最佳答案

我经常使用的另一个解决方案,尽管有点老套,是将 android:focusable="true"android:focusableInTouchMode="true" 设置为父 View (LinearLayout 、RelativeLayout 等),如果我希望能够清除 EditText 的 clearFocus(),或者打开 Activity/Fragment 而无需第一个 EditText 自动聚焦。

关于android - android 对话框中的 clearFocus 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17710743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com