Skip to content

Instantly share code, notes, and snippets.

@cfirmo33
Last active January 21, 2016 15:51
Show Gist options
  • Save cfirmo33/f172471d54320e950182 to your computer and use it in GitHub Desktop.
Save cfirmo33/f172471d54320e950182 to your computer and use it in GitHub Desktop.
CheckLimiteWatcher
public class CheckLimiteWatcher implements TextWatcher{
private Context context;
private int limite;
private int totalAnterior = -1;
public CheckLimiteWatcher( Context context, int limite ) {
this.limite = limite;
this.context = context;
}
public void afterTextChanged( Editable s ) {
try {
if( s.toString().length() > limite ){
if( s.toString().length() > totalAnterior ){
Funcoes.showMensagem( context, "Campo limitado em "+limite+" letras" );
}
totalAnterior = s.toString().length();
s.delete( limite, s.toString().length() );
return;
}else{
totalAnterior = s.toString().length();
}
}
catch( NumberFormatException nfe ){}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment