i am trying to make a textbox that has its limit of 32 characters.
If someone enters value like 1234 the program must add 26 Zeros infront example
0000...1234
I have made the limit for 32 characters in xml
android:maxLength="32"
CodePudding user response:
public String appendChars(String string) {
int expectedSize = 32;
// 32 zeros string
String zeros = "00000000000000000000000000000000";
int inputLength = string.length();
// append and return
if (inputLength < expectedSize) {
string = zeros.substring(0, expectedSize - inputLength) string;
}
return string;
}
can do something like this
CodePudding user response:
You can try like this
getValue = editText.getText().toString();
int number = 32;
if(editText.length() < number){
number -= getValue.length();
for(int i=0; i< number; i ){
getValue =0;
}
editText.setText(getValue);
}