Android: imeoptions attributes

Source: Internet
Author: User

By default, the button in the lower-right corner of the soft keyboard is "Next". Click it to go to the next input box to keep the soft keyboard

Set Android: imeoptions ="Actiondone"In the left-side Navigation Pane, click "finish" at the bottom of the keyboard. The cursor remains on the original input box and the keyboard is closed.

Android: imeoptions = "Actionsend"Under the soft keyboard, it becomes "send". After clicking it, the cursor moves the next one.
How do I use imeoptions set here? The following code allows edittext to implement setoneditexceptionlistener. In the oneditaction method, the actionid corresponds to the imeoptions we set. The default actionids include editorinfo. ime_null, editorinfo. ime_action_send, and editorinfo. ime_action_done. In this way, the function keys in the lower right corner of the keyboard can be implemented based on different edittext.
package com.test;  

import com.test.main.TestAsyn;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

public class IMFActivity extends Activity implements OnEditorActionListener {

EditText etDefault;
EditText etEmail;
EditText etNumber;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imf_layout);

etDefault = (EditText)findViewById(R.id.default_content);
etEmail = (EditText)findViewById(R.id.email_content);
etNumber = (EditText)findViewById(R.id.number_content);
etDefault.setOnEditorActionListener(this);
etEmail.setOnEditorActionListener(this);
etNumber.setOnEditorActionListener(this);

}

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch(actionId){
case EditorInfo.IME_NULL:
System.out.println("null for default_content: " + v.getText() );
break;
case EditorInfo.IME_ACTION_SEND:
System.out.println("action send for email_content: " + v.getText());
break;
case EditorInfo.IME_ACTION_DONE:
System.out.println("action done for number_content: " + v.getText());
break;
}
//Toast.makeText(this, v.getText()+"--" + actionId, Toast.LENGTH_LONG).show();
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>  
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">

<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="No special rules" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="1111111111111" android:id="@+id/default_content"
android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow>
<TextView android:text="Email address:" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/email_content"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:inputType="text|textEmailAddress"
android:imeOptions="actionSend"></EditText>
</TableRow>
<TableRow>
<TextView android:text="Signed decimal number:" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="" android:id="@+id/number_content"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:inputType="number|numberSigned|numberDecimal"
android:imeOptions="actionDone"></EditText>
</TableRow>
</TableLayout>
</ScrollView>
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.