EditText switches the enter key of the Input Method software to jump to the next EditText or search. edittextenter

Source: Internet
Author: User

EditText switches the enter key of the Input Method software to jump to the next EditText or search. edittextenter

First, the enter key of the Input Method software can be changed, and can be changed to next, search, and so on.

For example, implement a login interface

The Code is as follows:

<RelativeLayout

Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent" android: paddingLeft = "@ dimen/activity_horizontal_margin"
Android: paddingRight = "@ dimen/activity_horizontal_margin"
Android: paddingTop = "@ dimen/activity_vertical_margin"
Android: paddingBottom = "@ dimen/activity_vertical_margin" tools: context = ". MainActivity"> <EditText

Android: id = "@ + id/et_username"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: hint = "username"
Android: imeOptions = "actionNext"
Android: nextFocusForward = "@ + id/et_password"
Android: singleLine = "true"
/>
<EditText
Android: id = "@ + id/et_password"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: hint = "password"
Android: imeOptions = "actionDone"
Android: layout_below = "@ id/et_username"
Android:NextFocusForward= "@ + Id/btn_login"
Android: singleLine = "true"
/>
<Button
Android: id = "@ + id/btn_login"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "login"
Android: layout_below = "@ id/et_password"
/>
</RelativeLayout>

 

Android: imeOptions = "actionNext" // you can specify the enter function for the input method, actionNext-Next actionSearch, and so on.

  Android: nextFocusForward = "@ + id/et_password"// Specify the focus of the next view

In this way, after you enter username, press the next step of the Input Method and you will be transferred to the password input box. (These two attributes are the attributes of the parent view, so)

 

After you enter the password, the EditText of the password has the attributeAndroid: imeOptions = "actionDone", you can also listen to it

The Code is as follows:

EditText etPassWord = (EditText) findViewById (R. id. et_password );
EtPassWord. setoneditexceptionlistener (new TextView. oneditexceptionlistener (){
@ Override
Public boolean oneditexception (TextView v, int actionId, KeyEvent event ){
If (actionId = EditorInfo. IME_ACTION_DONE ){
Toast. makeText (MainActivity. this, "Login", Toast. LENGTH_SHORT). show ();
//... Implement the login function
}
Return false;
}
});

 

This is my first technical blog. I hope you will like it and have some questions. I also hope you can communicate and make progress together.

There will be more articles on android technology in the future.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.