How to create EditText numeric (signed and unsigned decimal) from java code

为君一笑 提交于 2019-12-11 07:39:22

问题


this is a loop that creates a table of EditText and I wish they were numerical

for (int i = 0; i < 3; i++) {

tableRow = new TableRow(this); //oggetto di tipo tableRow
tableRow.setGravity(Gravity.CENTER);

for (int j = 0; j < 3 ; j++) {

values[i][j] = new EditText(this);
values[i][j].setText(" " + array[count]);
values[i][j].setPadding(10, 10, 10, 10);//spaziatura di ogni cella per i quattro lati
tableRow.addView(values[i][j]);
count++;
}

tableLayout.addView(tableRow);  
}

回答1:


values[i][j].setInputType(InputType.TYPE_CLASS_NUMBER);

you can use the above line of code

Update try the below and thier combination

I've tried combining flags (in desperation to see if it would work):

values[i][j].setInputType(InputType.TYPE_CLASS_NUMBER);
values[i][j].setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL)
values[i][j].setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED)

refer this link for more inputtypes



来源:https://stackoverflow.com/questions/10302304/how-to-create-edittext-numeric-signed-and-unsigned-decimal-from-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!