Michael_D
Michael_D

Reputation: 11

Changing next button to done button on soft keyboard doesn't work

When the user clicks an icon in the action bar, an AlertDialog opens to save the data. To enter the name of the file, a soft keyboard appears. In this keyboard I want to change the ENTER button with a DONE. I applied ".setImeOptions(EditorInfo.IME_ACTION_DONE);" but it doesn't work. This is my code for the AlertDialog:

public void openSaveBox (){

    final AlertDialog ad = new AlertDialog.Builder(this).create();
    ad.setTitle("OCRA score bewaren");
    ad.setMessage("Geef een bestandsnaam in:");
    final EditText input = new EditText(this);        
    ad.setView(input);

    ad.setButton2("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String file = input.getText().toString();
            bewaren(file);
            ad.dismiss();
        }
    });
    ad.setButton("Annuleren", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ad.dismiss();
        }
    });

    ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);

    ad.show();
}

What am I doing wrong?

Upvotes: 1

Views: 412

Answers (1)

Collins Abitekaniza
Collins Abitekaniza

Reputation: 4578

Set the InputType for the Edit text input before ImeOptions i.e

  input.setInputType(EditorInfo.TYPE_CLASS_TEXT);
  input.setImeOptions(EditorInfo.IME_ACTION_DONE);

Upvotes: 2

Related Questions