Android: Limiting EditText to numbers

后端 未结 5 426
别跟我提以往
别跟我提以往 2020-12-20 12:39

When creating an EditText in the java portion of the application, how do you limit it to numbers like you would in the xml? For example:

new EditText(this);         


        
5条回答
  •  -上瘾入骨i
    2020-12-20 13:02

    Something like this perhaps ?

    EditText text = new EditText(this);
    text.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
    

提交回复
热议问题