-1

I have an AlertDialog that appears once a button is clicked, and placed there an EditText I want the user to fill with alphanumerics characters. If it wasn't dynamically created and put in the xml file I would have set something like android:digits="abcdefghijklmnopqrstuvwxyz1234567890 ". Does anyone know how could I proceed? My code is this:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Insert text");

    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);

    builder.setPositiveButton("CREATE", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do something
            }
        });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

    builder.show();
GondraKkal
  • 87
  • 2
  • 16

1 Answers1

1

Simple answer as described here.

setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyz1234567890 "));
creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • 1
    GREAT! Ok I placed it just before the builder.setView line and all works, but now I get an annoying thing I would like to change: the keyboard that appears when I click the dialog shows up starts from the "symbols page" and not from the normal characters. Commenting your suggestion gets it back to what I would like to be shown. Ideas? – GondraKkal Jun 22 '17 at 08:04
  • Sorry @creativecreatorormaybenot, but if you can give me a hand here it would be really great! – GondraKkal Jun 23 '17 at 07:49