estoy tratando de hacer en en un EditText
al escribir números en automático se pongan las famosas diagonales en tiempo real. esto con el fin de que mi cadena de números se vea como una fecha.
sin embargo al escribir en ese EditText tengo el siguiente error:
3896-3896/com.u_style E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.u_style, PID: 3896
java.lang.StringIndexOutOfBoundsException: length=0; regionStart=0; regionLength=6
at java.lang.String.startEndAndLength(String.java:588)
at java.lang.String.substring(String.java:1475)
at com.u_style.MenuActivity$9.beforeTextChanged(MenuActivity.java:803)
at android.widget.TextView.sendBeforeTextChanged(TextView.java:7602)
at android.widget.TextView.access$900(TextView.java:246)
at android.widget.TextView$ChangeWatcher.beforeTextChanged(TextView.java:9553)
at android.text.SpannableStringBuilder.sendBeforeTextChanged(SpannableStringBuilder.java:954)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:464)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:435)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30)
at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:121)
at android.widget.TextView.doKeyDown(TextView.java:5727)
at android.widget.TextView.onKeyDown(TextView.java:5538)
at android.view.KeyEvent.dispatch(KeyEvent.java:2650)
at android.view.View.dispatchKeyEvent(View.java:7673)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:373)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1422)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2117)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1548)
at android.app.Dialog.dispatchKeyEvent(Dialog.java:747)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2044)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4022)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3996)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3499)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3575)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3632)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3499)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5819)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5799)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5770)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3240)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
y esta es mi función:
editTextVenc.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
String texto = editTextVenc.getText().toString().substring(0,6);
if (texto.length() == 2) {
editTextVenc.setText(texto + "/");
editTextVenc.setSelection(texto.length() + 1);
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
espero me puedan ayudar.