Last active
January 21, 2016 15:51
-
-
Save cfirmo33/f172471d54320e950182 to your computer and use it in GitHub Desktop.
CheckLimiteWatcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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