Raluca Lucaci
Raluca Lucaci

Reputation: 2153

EditText - next button from keyboard - implementation

I have an EditText , after I write something and I click next i want to do a call to server. for example if i have edittext a, how I specify that the action has to happen just after I click next ? I suppose that a.setOnClickLisner is not ok

Thank you in advance , Raluca

Upvotes: 0

Views: 1363

Answers (2)

Noby
Noby

Reputation: 6612

Try this...

editText = (EditText) findViewById(R.id.editText);

editText.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER) {

                                    // PLACE CODE FOR CALLING SERVER.

                    return false;
                }
                return false;
                    }
});

Upvotes: 1

Niranj Patel
Niranj Patel

Reputation: 33258

try this....

EditText.setOnEditorActionListener(new OnEditorActionListener()
{

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
    {

        if(actionId==EditorInfo.IME_ACTION_NEXT) 
        {
                //Write your code here
}

    return false;
    }
});

Upvotes: 1

Related Questions