I have the following Login class.
public class LoginActivity extends ProgressBarActivity implements LoginActivityContract.View {
private final static String TAG = LoginActivity.class.getSimpleName();
LoginActivityPresenter presenter;
LoginActivityContract.LifeCycle onLifeCycle;
LoginActivityContract.Action onAction;
public TextView login;
private TextView password;
private Switch login_recordar_rut;
private Button loginButton;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView texto_version = findViewById(R.id.txt_version);
String versionName = BuildConfig.VERSION_NAME;
texto_version.setText(versionName);
login = (TextView) findViewById(R.id.login);
password = (TextView) findViewById(R.id.password);
login_recordar_rut = findViewById(R.id.login_recordar_rut);
loginButton = (Button) findViewById(R.id.login_button);
final Activity padre = this;
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View view = padre.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
if (!login.getText().equals("")) {
enableForm(false);
String loginText = login.getText().toString().replaceAll("\-", "").replaceAll("\.", "");
onAction.onLoginClick(loginText, password.getText().toString(), login_recordar_rut.isChecked());
} else {
showToolTipSB("Formato de Rut incorrecto...");
}
}
});
tannerApplication app = (tannerApplication) getApplication();
presenter = new LoginActivityPresenter(this,
app.getLocalStorage(),
app.getServerAccessPointSDK(),
app.getServerAccessPoint(),
this);
onLifeCycle = presenter;
onAction = presenter;
login.addTextChangedListener(new MaskWatcher(login.toString()));
}
public void enableForm(boolean isEnabled) {
login.setEnabled(isEnabled);
password.setEnabled(isEnabled);
}
public void setFocusBoton() {
return;
}
@Override
protected void onResume() {
super.onResume();
onLifeCycle.onResume(getIntent());
}
@Override
protected void onPause() {
super.onPause();
onLifeCycle.onPause();
}
@Override
public void setLoginText(@NonNull String text) {
login.setText(text);
}
@Override
public void setPasswordText(@NonNull String text) {
password.setText(text);
}
@Override
protected int getLayoutId() {
return R.layout.activity_login;
}
@Override
public void showContent() {
super.showContent();
}
@Override
public void showProgress() {
super.showProgress();
}
@Override
public void showToolTip(int msg) {
super.showToolTip(msg);
}
@Override
public void showToolTipSB(String msg) {
super.showToolTipSB(msg);
}
public void showToolTipSB(int msg) {
super.showToolTipSB(msg);
}
@Override
public void startRegisterActivity(@NonNull Bundle extras) {
finish();
}
@Override
protected boolean EjecutaronBackPressed() {
return true;
}
}
As you can see, it calls MaskWatcher which is another class, passing the TextView login parameter.
The MaskWatcher class is as follows.
public class MaskWatcher implements TextWatcher {
private boolean isRunning = false;
private boolean isDeleting = false;
private final String mask;
private EditText rutNumber;
public MaskWatcher(String mask) {
Log.i("MaskWatcher","String mask"+mask);
this.mask = mask;
}
public static MaskWatcher buildCpf() {
return new MaskWatcher(" ");
}
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
isDeleting = count > after;
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
String valortext = editable.toString();
Log.i("MaskWatcher","Valor valortext"+valortext);
if(valortext.equals(""))
{
Log.i("MaskWatcher","Valor valortext 0"+valortext);
valortext = "0";
}
else
{
Log.i("MaskWatcher","Valor valortext !0"+valortext);
FormatearRUT(valortext); //funcion que formateara el rut
}
}
public String FormatearRUT(String rut) {
Log.i("MaskWatcher","FormatearRUT valor"+rut);
int cont = 0;
String format;
rut = rut.replace(".", "");
rut = rut.replace("-", "");
format = "-" + rut.substring(rut.length() - 1);
for (int i = rut.length() - 2; i >= 0; i--) {
format = rut.substring(i, i + 1) + format;
cont++;
if (cont == 3 && i != 0) {
format = "." + format;
cont = 0;
}
}
Log.i("MaskWatcher","FormatearRUT valorformat"+format);
return format;
}
}
At the moment of entering a data in the TextView you need to give it the RUT format, but I can not find the way it is "printed in the TextView", how can I do it?