I am working on a calculator app just like the phones have, I am taking the numbers with buttons. I am using a string builder, when user presses to a new button string appends. Just like when you press button2 it adds number "2" to the string, then you press 5, so the new string is "25" and it goes like this and shows the string on a textView there is no problem. The problem is I want to limit the string builder like 8 digits. I limit the textView digit number but can not do it for the string builder. TextView has 8 digit restriction, so it does not show the 9th value but string accepts the 9th value. I used some codes from developer.android but can not find a solution. How can I limit the string builder length?
The code for limiting the textView;
int maxLength = 8; //at the top of the class
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(maxLength);
myTv.setFilters(filters);
The code; tried to limit the StringBuilder length;
public StringBuilder myStbuilder;
myStbuilder= new StringBuilder(); myStbuilder.setLength(maxLength);