gpt4 book ai didi

Android: AutoCompleteTextView 隐藏软键盘

转载 作者:可可西里 更新时间:2023-11-01 18:49:28 26 4
gpt4 key购买 nike

我有一个 AutoCompleteTextView,它像往常一样在用户键入 3 个字母后提供建议。我想要一次触摸建议列表以隐藏软键盘。我在下面对表格布局所做的操作仅在单击建议列表以外的任何地方时才隐藏键盘。

XML

<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >

<AutoCompleteTextView
android:id="@+id/auto_insert_meds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="15"
android:inputType="textVisiblePassword|textMultiLine"
android:scrollHorizontally="false"
android:text=""
android:textSize="16sp" />
</TableRow>

Java

TableLayout tbl = (TableLayout) findViewById(R.id.main_table);
tbl.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
});

自定义列表的 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/medlist_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/med_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollHorizontally="false"
android:padding="3dp"
android:textColor="@android:color/white" />

</LinearLayout>

最佳答案

使用 OnItemClickListener。希望这有效:)

AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.auto_insert_meds);

text.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(arg1.getWindowToken(), 0);

}

});

已更新

使用这个

in.hideSoftInputFromWindow(arg1.getApplicationWindowToken(), 0);

而不是-

in.hideSoftInputFromWindow(arg1.getWindowToken(), 0);

关于Android: AutoCompleteTextView 隐藏软键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14679264/

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