use*_*281 14 android enter key keypress xamarin
几个星期前我开始使用Xamarin Studio,但无法找到下一个问题的解决方案:创建了一个包含序列号的edittext.我想Enter在按下之后运行一个功能.它工作正常,当我按下时Enter,该功能运行没有失败,但我无法修改edittext的内容(我不能输入它).
代码:
EditText edittext_vonalkod = FindViewById<EditText>(Resource.Id.editText_vonalkod);
edittext_vonalkod.KeyPress += (object sender, View.KeyEventArgs e) =>
{
if ((e.Event.Action == KeyEventActions.Down) && (e.KeyCode == Keycode.Enter))
{
//Here is the function
}
};
Run Code Online (Sandbox Code Playgroud)
这是控件的代码:
<EditText
p1:layout_width="wrap_content"
p1:layout_height="wrap_content"
p1:layout_below="@+id/editText_dolgozo_neve"
p1:id="@+id/editText_vonalkod"
p1:layout_alignLeft="@+id/editText_dolgozo_neve"
p1:hint="Vonalkód"
p1:text="1032080293"
p1:layout_toLeftOf="@+id/editText_allapot" />
Run Code Online (Sandbox Code Playgroud)
我尝试使用edittext_vonalkod.TextCanged它的参数,保留问题.我可以修改内容但无法处理Enter密钥.
谢谢!
Ale*_*des 15
最好的方法是使用EditorAction设计为在Enter按键上触发的事件.它将是这样的代码:
edittext_vonalkod.EditorAction += (sender, e) => {
if (e.ActionId == ImeAction.Done)
{
btnLogin.PerformClick();
}
else
{
e.Handled = false;
}
};
Run Code Online (Sandbox Code Playgroud)
并且能够更改XML上Enter按钮使用的文本imeOptions:
<EditText
p1:layout_width="wrap_content"
p1:layout_height="wrap_content"
p1:layout_below="@+id/editText_dolgozo_neve"
p1:id="@+id/editText_vonalkod"
p1:layout_alignLeft="@+id/editText_dolgozo_neve"
p1:hint="Vonalkód"
p1:text="1032080293"
p1:layout_toLeftOf="@+id/editText_allapot"
p1:imeOptions="actionSend" />
Run Code Online (Sandbox Code Playgroud)
当按下的键为ENTER时,您需要将事件标记为未处理.将以下代码放在KeyPress处理程序中.
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
{
// Code executed when the enter key is pressed down
}
else
{
e.Handled = false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15970 次 |
| 最近记录: |