加载 View 时,我想强制 SIP 打开并显示带有数字的键盘。另外,我想要一个 editText View 接受来自 SIP 的字母和数字输入
XML
<EditText android:id="@+id/search_bus_by_num_keyword"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:lines="1" android:layout_weight="1"
android:inputType="numberDecimal"
/>
Code
editTextSearchKeyword = (EditText) context.findViewById(R.id.search_bus_by_num_keyword);
editTextSearchKeyword.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
context.hideSIP(editTextSearchKeyword);
searchRoute();
return true;
}
return false;
}
});
editTextSearchKeyword.setText(searchKeyword);
editTextSearchKeyword.requestFocus();
InputMethodManager mgr = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editTextSearchKeyword, InputMethodManager.SHOW_FORCED);
加载 View 时: http://pwong.name/sip_01.png
当我将 SIP 从数字更改为字母时: http://pwong.name/sip_02.png ,我无法将 Letter 输入到 editText View 。
如果我将 android:inputType="numberDecimal"设置为 editText,是否可以同时输入数字和字母?是否可以在运行时更改 android:inputType?
最佳答案
参见 this关于如何在代码中更改 InputType 的问题。参见 this EditText 输入类型的链接。至于你的要求“我想强制 SIP 打开并显示带数字的键盘。另外,我想要一个 editText View 接受来自 SIP 的字母和数字输入”——我不明白。我认为 EditText 不能有多种输入模式。
关于android - android :inputType of EditText View set to "numberDecimal"时接受SIP输入的数字和字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6985241/