Louis Sherwood
Louis Sherwood

Reputation: 147

EditText.SetOnEditorActionListener

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.

Upvotes: 1

Views: 8129

Answers (1)

Cheesebaron
Cheesebaron

Reputation: 24460

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

Upvotes: 8

Related Questions