Java tutorial
//package com.java2s; import android.text.InputFilter; import android.text.InputType; import android.widget.EditText; public class Main { /** * Adds input filters to supplied edit text to allow only: * A-Z, a-z, 0-9, and special characters (%$!@) * @param viewToFilter * @return */ public static EditText setNameInputFilters(EditText viewToFilter) { viewToFilter.setInputType(InputType.TYPE_CLASS_TEXT); viewToFilter.setFilters(new InputFilter[] { new InputFilter.LengthFilter(20) }); return viewToFilter; } }