private OnKeyListener onKeyListener = new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_ENTER){
/*隐藏软键盘*/
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(inputMethodManager.isActive()){
inputMethodManager.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
}
if (mEtNum.getText().toString() == null
|| mEtNum.getText().toString().equals("")) {
showToast("内容");
} else {
requestSearch();
}
return true;
}
return false;
}
};
xml文件添加属性
android:inputType=”textMultiLine”
android:imeOptions=”actionNone”