Set max text length for TextView - Android User Interface

Android examples for User Interface:TextView

Description

Set max text length for TextView

Demo Code


//package com.java2s;

import android.text.InputFilter;

import android.widget.TextView;

public class Main {
    /**/*from   w  ww. j a  v  a2  s .  c  om*/
     * Set max text length for textview
     ****/
    public static void setMaxLength(TextView textView, int maxLength) {

        if (textView == null) {
            throw new NullPointerException("TextView cannot be null");
        }

        InputFilter[] fArray = new InputFilter[1];
        fArray[0] = new InputFilter.LengthFilter(maxLength);
        textView.setFilters(fArray);
    }
}

Related Tutorials