EditText.SetOnEditorActionListener

Lou*_*ood 0 android xamarin.android android-edittext

我完全不知道在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应用程序中获得此功能?

感谢您提供的任何帮助.

Che*_*ron 6

在Xamarin.Android中,侦听器将转换为C#事件.您发布的Java代码在单声道等效转换为此代码:

var ed = FindViewById<EditText>(Resource.Id.search);
ed.EditorAction += (sender, args) =>
    {
        if (args.ActionId == ImeAction.Send)
        {
            SendMessage();
            args.Handled = true;
        }
    };
Run Code Online (Sandbox Code Playgroud)