Using Edit Text IME Option in Android App.

An Editor Info is most useful class when you have to deal with any type of user input in your Android application. For e.g. in login/registration/search operations we can use it for more accurate keyboard input.

Example:

 

mainactivity.xml:

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
          android:imeOption="actionDone" // you can set any name on this keyboard button.
android:ems="10" />

 

MainActivity.java:

public class MainActivity extends Activity {

EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.mainactivity);

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

editText.setOnEditorActionListener(new DoneOnEditorActionListener());

}

class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Toast.makeText(MainActivity.this, "Click on Done Button", Toast.LENGTH_SHORT).show();
}
return false;
}
}
}