Android:AutoCompleteTextView隐藏软键盘 [英] Android: AutoCompleteTextView hide soft keyboard
本文介绍了Android:AutoCompleteTextView隐藏软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个AutoCompleteTextView,它照常在用户键入3个字母后提供建议.我想一次触摸建议列表以隐藏软键盘. 下面我对表格布局所做的一切仅在单击建议列表以外的任何地方时才隐藏键盘.
I have an AutoCompleteTextView which as usual provides suggestions after a user types 3 letters. I want once once I touch the suggestion list to hide the soft keyboard. What I have done below with the table layout hides the keyboard only when clicking anywhere but the suggestion list.
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隐藏软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文