我在Mono for Android中的EditText控件遇到了一些非常奇怪的问题.我的解决方案是针对2.3而我正在调试T Mobile VivaCity.这是我的EditText的AXML
<EditText
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ctl_searchText" />
Run Code Online (Sandbox Code Playgroud)
当我显示包含EditText的视图时,键盘会自动出现,这不是问题.问题是我无法通过点击键盘上的数字输入任何数字,唯一可以在文本字段中显示数字的方法是,如果我按住键并从上下文菜单中选择数字.虽然一旦我使用这种方法输入了一个数字,我就无法将其删除.我已经尝试了各种输入方法,并在SO中寻找类似的问题无济于事.这听起来像是设备的问题吗?或者是否有一些明显我在代码/ AXML中没有做的事情?
==编辑==
我认为我已经缩小了问题范围,它与EditText上使用的KeyPress事件处理程序有关.由于EditText表示搜索字段,我添加了属性android:singleLine ="true"以停止返回键添加额外的行,而是说"完成".当我向控件添加一个KeyPress事件处理程序时,这就是它阻止我输入数字,但没有处理程序它再次开始正常运行.这是我有的:
<EditText
android:id="@+id/ctl_searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
Run Code Online (Sandbox Code Playgroud)
EditText ctl_searchText = FindViewById<EditText>(Resource.Id.ctl_searchText);
ctl_searchText.KeyPress += (object sender, View.KeyEventArgs e) =>
{
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
{
Toast.MakeText (this, ctl_searchText.Text, ToastLength.Short).Show ();
e.Handled = true;
}
};
Run Code Online (Sandbox Code Playgroud)
使用此代码,我无法在文本字段中输入数字,但我可以输入字母.当我删除事件处理程序时,它再次起作用,允许我输入所有字符.我要继续调查,这很奇怪.
android xamarin.android android-input-method android-edittext android-2.3-gingerbread
我完全不知道在EditText控件上为imeOption设置"actionSearch"实现一个动作监听器.
我已经查看了Android文档,但我在Mono中找不到对它的支持.我已经尝试实现TextView.IOnEditorActionListener,但我找不到要覆盖的OnEditorAction方法.
这是我正在尝试使用的代码:
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到我尝试设置动作监听器,Mono中没有我能找到的OnEditorActionListener,在它的位置它要求TextView.IOnEditorActionListener,我找不到任何显示你将如何在Mono中接近它的东西.这是不支持的,还是有办法在Mono for Android应用程序中获得此功能?
感谢您提供的任何帮助.
android ×2