EditText.SetOnEditorActionListener

故事扮演 提交于 2019-12-12 03:52:49

问题


I'm completely at a loss for implementing an action listener for the imeOption setting "actionSearch" on an EditText control.

I have looked at the Android Documentation for doing this, but I can't find support for it in Mono. I've tried implementing a TextView.IOnEditorActionListener, but I can't find the OnEditorAction method to override.

This is the code I'm trying to use:

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

Everything is fine until I try to set the action listener, there is no OnEditorActionListener in Mono that I can find, in its place it asks for a TextView.IOnEditorActionListener and I can't find anything that shows how you would approach this in Mono. Is it that this is just not supported or is there a way to get this functionality in a Mono for Android app?

Thank you for any help you can supply.


回答1:


In Xamarin.Android the listeners are converted into C# Events instead. The Java code you posted converts to this in the mono equivalent:

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


来源:https://stackoverflow.com/questions/16317083/edittext-setoneditoractionlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!