我有一个 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>
爪哇
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>