Androidedittextinputtype and android:imeoptions= "Actiondone"

Source: Internet
Author: User

First, the Android software disk incident response in Android, sometimes need to edittext implementation of the software disk monitoring scenario. When Android presses the soft keyboard, it responds to completion, send, search, or other events. Google offers some of the editorinfo and keyevent ways to achieve the functionality we need. Detailed studies are available: Editorinfo.class and Keyevent.class. Enter the ENTER key to hide the input keyboard method:

If the layout contains more than one edittext, you can set the android:singleline= "true" for each EditText control, and the eject floppy input key will be next, until the last one gets the focus to show as done. After clicking Done, hide the soft key input disk. Set the Imeoptions property of EditText to Android:imeoptions= "Actiondone", then click Enter to hide the input method, whether it is the last edittext or not.

Listen for the Enter event and write the event response for enter. Set the Onkeylistener of the text box, when KeyCode ==keyevent.keycode_enter, indicates that the ENTER key is pressed, you can write your own event response function.

The XML file is as follows:

1    <EditText2 Android:id= "@+id/edittextid"3 Android:layout_width= "Fill_parent"4 Android:layout_height= "50DP"5 android:imeoptions= "Actiondone"6 Android:hint= "@string/task_new_one"7 android:textsize= "15SP"8 Android:singleline= "true"9 Android:paddingleft= "5DP"Ten android:layout_gravity= "Center" One Android:background= "@drawable/rectangle" A Android:inputtype= "text" - > - </EditText>

Set the EditText IME options property to a different value, and the ENTER key can display different text or patterns.
Actionnone: Enter, press the cursor to the next line
Actiongo:go,
Actionsearch: a magnifying glass
Actionsend:send
Actionnext:next
Actiondone:done, hide soft keyboard, even if not the last text input box

Change the default keyboard display text by modifying the android:imeoptions. The common constant values are as follows:
    1. Actionunspecified unspecified, corresponding to constant editorinfo.ime_action_unspecified. Effect:
    2. Actionnone no action, corresponding to the constant Editorinfo.ime_action_none effect:
    3. Actiongo, corresponding to the constant Editorinfo.ime_action_go effect:
    4. Actionsearch Search, corresponding to the constant Editorinfo.ime_action_search effect:
    5. Actionsend send, corresponding to the constant Editorinfo.ime_action_send effect:
    6. Actionnext next, corresponding to the constant Editorinfo.ime_action_next effect:
    7. Actiondone complete, corresponding to the constant Editorinfo.ime_action_done effect:
Java code: 1 EditText inputtext = (EditText) Findviewbyid (r.id. Edittextid); 2 inputtext.setimeoptions (editorinfo.ime_action_done);

  

To add a listener event:
1  Private FinalEdittext.oneditoractionlistener Editoractionlistener =2 NewTextview.oneditoractionlistener () {3 @Override4  Public BooleanOneditoraction (TextView V,intActionId, KeyEvent event) {5 if(ActionId = = Keyevent.action_down | | actionid = =Editorinfo.ime_action_done) {6 //Business code7 haoment.createtest (Test.getid (), V.gettext (). toString ());8Uiutils.hidesoftkeyboard (Getapplicationcontext (), Haotest. This);9V.settext ("");Ten V.clearfocus (); One Handler.post (updateview); A } - return true; - } the};
However, if the input method of the phone is not the built-in input method, but other third-party input method, then the software disk return will be unresponsive problems. To prevent this sort of thing, add the red part, responding to its keyevent. In this case, you need to add an event response in your code.

Inputkey = (EditText) Findviewbyid (R.id.contactsearch_edittext);
Inputkey.addtextchangedlistener (watcher);

Inputkey.setonkeylistener (New View.onkeylistener () {
@Override
public boolean OnKey (View v, int keycode, keyevent event) {
    

if (Keyevent.keycode_enter = = KeyCode && event.getaction () = = Keyevent.action_down) {
Handler.post (Updateview);
return true;
}
return false;
}
});
Responding to keyboard content
Public Textwatcher watcher = new Textwatcher () {

@Override
public void beforetextchanged (charsequence charsequence, int i, int i2,int i3) {

}

@Override
public void ontextchanged (charsequence charsequence, int i, int i2, int i3) {

}

@Override
public void aftertextchanged (Editable Editable) {

Handler.post (Updateview);

}
};

Second, the Android input type according to the content to be entered to display the corresponding software disk, can be achieved by modifying the Android:inputtype. This is some of the commonly used input types.
Android:inputtype= "None"--Enter ordinary characters android:inputtype= "text"--Enter ordinary characters android:inputtype= "textcapcharacters"-- Enter normal character android:inputtype= "Textcapwords"--the first letter size android:inputtype= "textcapsentences"--only the initial letter size Android:inputtype = "Textautocorrect"--the first two auto-complete android:inputtype= "Textautocomplete"--the first two auto-complete android:inputtype= "Textmultiline"-- Multi-line input android:inputtype= "textimemultiline"--Input method multiple lines (not necessarily supported) android:inputtype= "Textnosuggestions"--Do not prompt Android: Inputtype= "Texturi"--uri format android:inputtype= "Textemailaddress"--e-mail address format android:inputtype= "Textemailsubject"-- Message subject format android:inputtype= "Textshortmessage"--Short message format android:inputtype= "Textlongmessage"--long message format android:inputtype= " Textpersonname "--name format android:inputtype=" Textpostaladdress "--Postal format android:inputtype=" Textpassword "--Password format android: Inputtype= "Textvisiblepassword"--Password visible format android:inputtype= "Textwebedittext"-text format as a Web Form android:inputtype= " TextFilter "--Text filter format android:inputtype=" textphonetic "--Pinyin input format android:inputtype=" number "--Digital format android:inputtype=" Numbersigned "--Signed digital format android:Inputtype= "Numberdecimal"--floating point format with decimal point android:inputtype= "Phone"--dial pad android:inputtype= "datetime" Android: Inputtype= "Date"--date keyboard android:inputtype= "Time"--temporal keyboard
The Password Box property android:password= "True"   the content displayed by EditText is automatically asterisks, and the content will become a * typeface within 1 seconds of input. Pure Digital android:numeric= "true"   allow IME to automatically turn into a digital input keyboard, while allowing only 0-9 of digital inputs to allow only android:capitalize= "Haotest"   allow only accept input haotest , generally used for password authentication android:editable= "False"   set EditText non-editable android:singleline= "true"   force input on a single line Android:ellip Size= "End"   auto-hide trailing overflow data, typically used for long lines of text when not all displayed (partial attribute reference network: http://blog.csdn.net/lushengchu_luis/article/details/ 8699791, http://www.eoeandroid.com/thread-313140-1-1.html)

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.