AutoCompleteTextView无法输入第二个字符(Nexus 5X)

时间:2018-01-31 09:47:16

标签: android autocompletetextview

我有一个ChildFragment,它使用菜单CustomView扩展ParentFragment。 CustomView扩展了LinearLayout,这个布局有一个AutoCompleteTextView:

<AutoCompleteTextView
            android:id="@+id/searchId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/buttonId"
            android:background="@null"
            android:dropDownSelector="@drawable/list_selector_bk"
            android:dropDownVerticalOffset="@dimen/margin_parts"
            android:ellipsize="end"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:hint="@string/search_hint"
            android:imeOptions="actionSearch"
            android:inputType="text|textAutoComplete|textNoSuggestions"
            android:maxLines="1"
            android:paddingTop="5dp"
            android:textColor="@color/white"
            android:textCursorDrawable="@drawable/actionbar_cursor"
            android:textSize="@dimen/font_size_normal" />

当我在AutoCompleteTextView中输入第二个字符时,会调用ChildFragment的onclick事件。请帮我找到这个问题。非常感谢。

更新:

class ChildFragment extends ParentFragment implements View.OnClickListener, DialogActionCallback {
    @Override
    public void onClick(View v) {
        // Show ABC dialog
    }
}

class HideFragment extends Fragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
    // Override methods
}

class ParentFragment extends HideFragment implements State, BaseInterface,
        DialogConst, OnDialogResultListener {
    protected CustomView customView;

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        customView = (CustomView) menu.findItem(R.id.action_menu_search).getActionView();
    }
}

action_menu_search.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_menu_search"
        android:icon="@drawable/btn_com_search_selector"
        android:showAsAction="always|collapseActionView"
        android:actionViewClass="xxx.CustomView"
        android:title="@string/action_menu_title_search"
        android:titleCondensed="@string/action_menu_title_search">
    </item>
    ....
</menu>

class CustomView extends LinearLayout implements MenuItem.OnActionExpandListener,
        View.OnClickListener, TextWatcher, View.OnKeyListener, View.OnFocusChangeListener,
        SearchController.Callback, ViewTreeObserver.OnGlobalLayoutListener,
        AdapterView.OnItemClickListener, View.OnTouchListener {

    private AutoCompleteTextView customView;

    public CustomView(Context context, AttributeSet attrs) {

        // layout = load layout contains AutoCompleteTextView 
        customView = (AutoCompleteTextView) layout.findViewById(R.id.searchId);
        customView.setOnKeyListener(this);
        customView.setOnFocusChangeListener(this);
        customView.setOnTouchListener(this);
        customView.setThreshold(0);
        customView.setDropDownBackgroundDrawable(new ColorDrawable(mContext.getResources()
                .getColor(R.color.bg_color_dark_gray)));
        customView.setOnItemClickListener(this);
    }

    @Override
    public void afterTextChanged(Editable s) {
        // Hide/show suggest dialog
    }

}

目的是在autocompleteview中输入字符时显示建议对话框。但是当快速输入第二个字符时,在Nexus 5x上发现了这个错误,并且显示了ABC对话框而不是建议对话框。对于许多设备没问题。对不起我的表情。谢谢你的回复。

1 个答案:

答案 0 :(得分:0)

我刚刚找到了解决方案:

如果建议清单没有数据 setDropDownHeight(1); 其他 setDropDownHeight(LayoutParams.WRAP_CONTENT);

但我不知道为什么?