Android:imeoptions Property

Source: Internet
Author: User

By default, the button in the lower-right corner of the soft keyboard is "next" and the next input box is clicked to keep the soft keyboard



Set android:imeoptions="Actiondone" , under the soft keyboard becomes "done", click the cursor remains on the original input box, and the soft keyboard off



android:imeoptions= "Actionsend"Under the soft keyboard becomes "send", click on the cursor to move the next

How to use the Imeoptions set here? As the following code, let EditText implement Setoneditoractionlistener, ActionId in the Oneditaction method corresponds to the imeoptions we set. The system default ActionId are: Editorinfo.ime_null, Editorinfo.ime_action_send, Editorinfo.ime_action_done and so on. In this way, we can implement different soft keyboard lower right corner function keys according to different edittext.

Java code
  1. Package com.test;
  2. Import Com.test.main.TestAsyn;
  3. Import android.app.Activity;
  4. Import Android.os.Bundle;
  5. Import android.view.KeyEvent;
  6. Import Android.view.inputmethod.EditorInfo;
  7. Import Android.widget.EditText;
  8. Import Android.widget.TextView;
  9. Import Android.widget.TextView.OnEditorActionListener;
  10. Import Android.widget.Toast;
  11. Public class Imfactivity extends Activity implements Oneditoractionlistener {
  12. EditText Etdefault;
  13. EditText Etemail;
  14. EditText Etnumber;
  15. /** Called when the activity is first created. * /
  16. @Override
  17. public void OnCreate (Bundle savedinstancestate) {
  18. super.oncreate (savedinstancestate);
  19. Setcontentview (r.layout.imf_layout);
  20. Etdefault = (EditText) Findviewbyid (r.id.default_content);
  21. Etemail = (EditText) Findviewbyid (r.id.email_content);
  22. Etnumber = (EditText) Findviewbyid (r.id.number_content);
  23. Etdefault.setoneditoractionlistener (this);
  24. Etemail.setoneditoractionlistener (this);
  25. Etnumber.setoneditoractionlistener (this);
  26. }
  27. @Override
  28. Public Boolean oneditoraction (TextView V, int ActionId, keyevent event) {
  29. switch (actionid) {
  30. Case Editorinfo.ime_null:
  31. SYSTEM.OUT.PRINTLN ("Null for default_content:" + v.gettext ());
  32. Break ;
  33. Case Editorinfo.ime_action_send:
  34. System.out.println ("Action Send for Email_content:" + v.gettext ());
  35. Break ;
  36. Case Editorinfo.ime_action_done:
  37. System.out.println ("Action done for Number_content:" + v.gettext ());
  38. Break ;
  39. }
  40. //toast.maketext (this, v.gettext () + "--" + ActionId, Toast.length_long). Show ();
  41. return true;
  42. }
  43. }
XML file:

XML code
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width= "fill_parent" android:layout_height="fill_parent">
  4. <tablelayout android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6. <TableRow>
  7. <TextView android:text="No special rules" android:id="@+id/textview01 "
  8. android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
  9. <EditText android:text="1111111111111" android:id="@+id/default_content "
  10. android:layout_width= "fill_parent" android:layout_height="wrap_content"></ EditText>
  11. </TableRow>
  12. <TableRow>
  13. <TextView android:text="Email address:" android:id="@+id/textview01"
  14. android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
  15. <EditText android:text= "" android:id= "@+id/email_content"
  16. android:layout_width= "fill_parent" android:layout_height="wrap_content "
  17. android:inputtype="text|textemailaddress"
  18. android:imeoptions="Actionsend"></EditText>
  19. </TableRow>
  20. <TableRow>
  21. <TextView android:text="Signed decimal number:" android:id="@+id/textview01"
  22. android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
  23. <EditText android:text= "" android:id= "@+id/number_content"
  24. android:layout_width= "fill_parent" android:layout_height="wrap_content "
  25. android:inputtype="Number|numbersigned|numberdecimal"
  26. android:imeoptions="Actiondone"></EditText>
  27. </TableRow>
  28. </tablelayout>
  29. </ScrollView>

Turn from:

http://liliang1222.iteye.com/blog/1130062

(GO) Android:imeoptions property

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.