How to increase max length character limit of edit text in Android button by 10 in every click?

282 Views Asked by At

Android maxLength: 500

EditText ed=(EditText)findViewById(R.id.edittext);

int maxLength= //current maxlength + 10 // im looking for the current max length code to add it with 10

ed.setFilters(new InputFilter[]{new 

InputFilter.LengthFilter(maxLength)});

The output will be a total of 510 maxLength character input in first click of button and on second click it will be 520 and so on and so fort.

1

There are 1 best solutions below

1
JakeB On

Pretty straight forward

button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        final int width = button.getLayoutParams().width + 10;
        final int height = button.getLayoutParams().height;
        button.setLayoutParams(new LayoutParams(width, height));
    }
 });

Since your first question wasn't very clear here is the update:

int maxLength = 500;

button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        maxlength = maxLength + 10;
        editText.setFilters(new InputFilter[] {
            new InputFilter.LengthFilter(maxLength)
        });
    }
 });