问题描述
我有一些很奇怪的问题,单声道的EditText控制为Android。我的解决方案的目标是2.3,我在T移动活泼调试。下面是我对的EditText
I am having some very strange problems with the EditText control in Mono for Android. My solution is targeting 2.3 and I am debugging on a T Mobile VivaCity. Here is my AXML for the EditText
<EditText
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ctl_searchText" />
当我告诉包含的EditText键盘会自动出现认为,这是没有问题的。问题是我无法通过敲击键盘上的数字键输入任何数字,我可以得到一个数字在文本字段中显示的唯一方法是,如果我按住键并从上下文菜单中选择数。虽然曾经我在使用这种方法,我则无法将其删除输入的数字。我已经试过各种输入法,并看看在SO无济于事类似的问题。这听起来像设备的问题吗?或者是有什么昭然若揭我不是在code / AXML干什么?
When I show the View containing the EditText the keyboard automatically appears, this is not a problem. The problem is I can't enter any numbers by tapping the numbers on the keyboard, the only way I can get a number to show in the text field is if I hold the key down and chose the number from a context menu. Although once I've entered a number in using this method I'm then not able to delete it. I've tried all sorts of input methods and had a look for similar issues in SO to no avail. Does this sound like an issue with the device? Or is there something glaringly obvious I'm not doing in the code/AXML?
== ==编辑
我想我已经缩小了问题了,它是与上的EditText使用的密钥preSS事件处理程序。由于重新的EditText presents搜索字段我已经添加属性android:单线=真,从增加一个额外的行停回车键,而是说完成。当我添加一个关键preSS事件处理程序来控制,这是当它停止从我输入数字,但没有处理它开始恢复正常工作。以下是我有:
I think I've narrowed the problem down, it has something to do with the KeyPress event handler used on the EditText. As the EditText represents a search field I have added the attribute android:singleLine="true" to stop the return key from adding an extra line and instead say "Done". When I add a KeyPress event handler to the control this is when it stops me from entering numbers, but without the handler it begins to function normally again. Here is what I have:
<EditText
android:id="@+id/ctl_searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
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;
}
};
有了这个code,我不能输入数字到文本字段,但是我可以输入字母。当我删除了事件处理一遍的作品,让我输入的所有字符。我要进行调查,这是很奇怪的。
With this code I cannot enter numbers into the text field, but I can enter letters. When I remove the event handler it works again, allowing me to enter all characters. I'm going to carry on investigating, this is very strange.
推荐答案
请cheack你不使用的。如果是刚检查安其(视图V,INT键code,KeyEvent的事件)方法返回真,如果监听器已经消耗的情况下,否则为false。在你的情况是这样的:
Please cheack that you doesn't use OnKeyListener. If yes just check that onKey (View v, int keyCode, KeyEvent event) method return True if the listener has consumed the event, false otherwise. In your case it something like this:
ctl_searchText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_ENTER){
//do smth
return true;
}
return fasle;
}
});
这篇关于MonoDroid的 - 的EditText输入法不会接受的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!