I try to set the "Done" button on the softkeyboard by using input.setImeOptions(EditorInfo.IME_ACTION_DONE);
but the "Done" button simply does not show on the softkeyboard.
Any suggestion please?
public void modif(int position) { AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); alert.setTitle("Modifica"); EditText input = new EditText(MainActivity.this); input.setImeOptions(EditorInfo.IME_ACTION_DONE); alert.setView(input); final Editable value = input.getText(); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(getApplicationContext(), value, Toast.LENGTH_LONG).show(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); }
First you need to set the android:imeOptions attribute equal to actionDone for your target EditText as seen below. That will change your 'RETURN' button in your EditText's soft keyboard to a 'DONE' button.
As stated in Android Documentation, IME Action directs the keyboard what type of action should be displayed. This depends on you (the developer) to change the IME Action according to your needs. For example, a text field intended to be used as a search bar would contain the search IME Action and so on…
android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: findViewById<EditText>(R.
It's probably because your input field is not single-lined.
Try adding
input.setSingleLine();
And you will see that pressing the action key of the keyboard will actually perform a 'done' action (i.e close the keyboard)
See http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_DONE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With