我一直致力于一个有3项活动的应用程序(让我们说A,B,C)
public void OnCreate(Bundle SavedInstanceBundle)
{
base.OnCreate(SavedInstanceBundle);
SetContentView(Resource.Layout.EditTextLayout);
EditText editText = FindViewById<EditText>(Resource.Id.editText);
//ADDING EVENT HANDLERS FOR EDITTEXT'S TEXTCHANGED AND KEYPRESSED EVENTS
editText.TextChanged += editText_TextChanged;
editText.KeyPressed += editText_KeyPressed;
}
private void editText_TextChanged (object sender, TextChangedEventArgs e)
{
}
private void editText_KeyPressed (object sender, View.KeyEventArgs e)
{
}
public override void OnBackPressed()
{
base.OnBackPressed();
this.finish();
}
这里的问题是当事件处理程序代码存在时,OnBackPressed就是 按下硬件后退时从未执行过。但是,当添加事件时 处理程序代码将被删除,最终OnBackPressed启动 工作正常。
答案 0 :(得分:0)
您可以确定用户是否按下了KeyPressed事件处理程序中的Back键:
private void editText_KeyPressed (object sender, View.KeyEventArgs e)
{
if (e.KeyCode == Keycode.Back)
{
this.Finish();
e.Handled = true;
return;
}
}