我对android中mono的edittext控件有一些非常奇怪的问题。我的解决方案是针对2.3,我正在T Mobile Vivacity上调试。这是我的编辑文本的axml

<EditText
    android:inputType="text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/ctl_searchText" />

当我显示包含编辑文本的视图时,键盘会自动出现,这不是问题。问题是我不能通过敲击键盘上的数字来输入任何数字,唯一能让数字显示在文本字段中的方法是我按住键并从上下文菜单中选择数字。尽管在使用此方法时输入了一个数字,但随后无法将其删除。我尝试过各种输入方法,在中查找了类似的问题,但都没有结果。这听起来像是设备的问题吗?或者在代码/axml中有明显的我没有做的事情吗?
=编辑=
我想我已经缩小了问题的范围,它与edittext上使用的keypress事件处理程序有关。由于edittext代表一个搜索字段,我添加了android:singleline=“true”属性来阻止return键添加额外的行,而是说“done”。当我向控件添加按键事件处理程序时,它会阻止我输入数字,但如果没有处理程序,它将再次正常工作。以下是我所拥有的:
<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;
    }
};

使用此代码,我不能在文本字段中输入数字,但可以输入字母。当我删除事件处理程序时,它再次工作,允许我输入所有字符。我要继续调查,这很奇怪。

最佳答案

请确认您没有使用OnKeyListener。如果是,只要检查onkey(view v,int keycode,keyevent event)方法是否返回true(如果侦听器已使用该事件),否则返回false。你的情况是这样的:

   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;
        }
   });

07-24 09:37