Java Code Examples for android.widget.TextView.setFilters()

The following are Jave code examples for showing how to use setFilters() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 6 votes
public static void setMaxLength(TextView textView, int length) {
    InputFilter[] inputFilters = textView.getFilters();
    ArrayList<InputFilter> inputFilterArray = new ArrayList<InputFilter>();

    if (inputFilters != null) {
        for (int i = 0; i < inputFilters.length; i++) {
            InputFilter inputFilter = inputFilters[i];

            if (!(inputFilter instanceof LengthFilter))
                inputFilterArray.add(inputFilter);
        }

    }
    inputFilterArray.add(new LengthFilter(length));
    textView.setFilters(inputFilterArray.toArray(new InputFilter[0]));
}
 
Example 2
Project: ViewCacheManager   File: MainActivity.java   View Source Code Vote up 6 votes
private View getItemView() {
    LinearLayout mItemLayout = new LinearLayout(this);
    mItemLayout.setGravity(Gravity.CENTER);
    mItemLayout.setOrientation(LinearLayout.VERTICAL);


    ImageView mImageView = new ImageView(this);
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(ui_dip2px(50), ui_dip2px(50));
    mImageView.setLayoutParams(mParams);
    mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);


    TextView mTextView = new TextView(this);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
    mTextView.setTextColor(Color.BLUE);

    mItemLayout.addView(mImageView);
    mItemLayout.addView(mTextView);


    return mItemLayout;
}