当 EditText 视图的 android:inputType 设置为“numberDecimal”时,接受来自 SIP 的数字和字母输入
加载视图时,我想强制 SIP 打开并显示带有数字的键盘。另外,我希望 editText 视图
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);
在加载视图时接受来自 SIP 的字母和数字输入: http://pwong.name/sip_01.png
当我将 SIP 从数字更改为字母时: http://pwong.name/sip_02.png ,我无法在 editText 视图中输入 Letter 。
如果我将 android:inputType="numberDecimal" 设置为 editText,是否可以同时输入数字和字母?是否可以在运行时更改 android:inputType ?
When a View loaded, I want to force SIP to open and show Keyboard with numbers. Also, I want a editText view accepts Letter and Number input from 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);
When the View loaded:
http://pwong.name/sip_01.png
When I change the SIP from Number to Letter:
http://pwong.name/sip_02.png , I cannot enter Letter to the editText view.
Is it possible to enter both of number and letter for a editText if I set android:inputType="numberDecimal" to it? Is it possible to change android:inputType at run time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关如何更改代码中的 InputType 的信息,请参阅此问题。有关 EditText 输入类型,请参阅此链接。至于您的要求“我想强制 SIP 打开并显示带有数字的键盘。另外,我想要一个 editText 视图接受来自 SIP 的字母和数字输入” - 我不明白。我认为 EditText 不能有多种输入模式。
See this question about how to change the InputType in code. See this link for the EditText input types. As far as your requirements of "I want to force SIP to open and show Keyboard with numbers. Also, I want a editText view accepts Letter and Number input from SIP" - I do not understand. I do not think you can have multiple modes of input for an EditText.
试试这个代码
try this code