How to handle the "done" ime button in edit text;

Shay Wilner 1,706 Reputation points
2023-10-30T17:30:39.0533333+00:00

Hello

In Xamarin android i try to handle with the " done " button of the virtual keyboard of the edit text

edittext.KeyPress += Edittext_KeyPress

private void Edittext_KeyPress(object sender, View.KeyEventArgs e)

{

}

how do i know if done button was clicked ?

Thanks

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,207 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 58,496 Reputation points Microsoft Vendor
    2023-10-31T03:01:37.47+00:00

    Hello,

    how do i know if done button was clicked ?

    You can do this by setting SetOnEditorActionListener.

    
    editText1.SetOnEditorActionListener(new OnEditorActionListener(editText1));
    
    

    Then you can implement TextView.IOnEditorActionListener interface, you can detect the done button click by actionId== ImeAction.Done. As note: Return true if you have consumed the action in the OnEditorAction, else false.

    internal class OnEditorActionListener : Java.Lang.Object, TextView.IOnEditorActionListener
    {
        private EditText editText1;
    
    
       public OnEditorActionListener(EditText editText1)
        {
            this.editText1 = editText1;
        }
    
    
       public bool OnEditorAction(TextView v, [GeneratedEnum] ImeAction actionId, KeyEvent e)
        {
            if( actionId== ImeAction.Done)
            {
                Console.WriteLine("Done");
            }
            return false;
        }
    }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful