逻辑很简单,当用户输入编辑文本的数字时,它会失去焦点,然后编辑文本会变得焦点,然后它会变成这样.但问题是当我点击后退空间我想在edittext之前返回再次输入数字.我试图在beforeTextChange中插入keyListener,但它没有工作.
private voID SetTextChange(final EditText etCurrent,final EditText etForward,final EditText etBack,final boolean isLast,final int currentposition){ etCurrent.addTextChangedListener(new TextWatcher() { @OverrIDe public voID beforeTextChanged(CharSequence s,int start,int count,int after) { } @OverrIDe public voID onTextChanged(CharSequence s,int before,int count) { if (etCurrent.getText().length() == 1 && !isLast ) { etCurrent.setTypeface(null,Typeface.norMAL); etCurrent.clearFocus(); etForward.requestFocus(); etForward.setCursorVisible(true); etCurrent.getBackground().setcolorFilter(getResources().getcolor(R.color.lavender_indigo),PorterDuff.Mode.SRC_Atop); } else if (etCurrent.length() == 0) { etCurrent.getBackground().setcolorFilter(getResources().getcolor(R.color.french_gray),PorterDuff.Mode.SRC_Atop); etCurrent.setTypeface(null,Typeface.SANS_serif.getStyle()); etCurrent.setTypeface(null,Typeface.norMAL); etCurrent.clearFocus(); etBack.requestFocus(); etBack.setCursorVisible(true); } if (etCurrent.length() != 0) { Integer currentKey = Integer.parseInt(etCurrent.getText().toString()); keyList.set(currentposition,currentKey); } else keyList.set(currentposition,-1); if (keyList.size() > 3) showToast(keyList.get(0) + " " + keyList.get(1) + " " + keyList.get(2) + " " + keyList.get(3)); } @OverrIDe public voID afterTextChanged(Editable s) { } }); /*curText.setonFocuschangelistener(new VIEw.OnFocuschangelistener() { public voID onFocusChange(VIEw arg0,boolean arg1) { curText = etCurrent; backText = etBack; curText.setText(""); } });*/ }
这也是我的EditText示例xml之一.(其他都是一样的)
<EditText androID:layout_column="1" androID:layout_columnWeight="1" androID:ID="@+ID/etActivationDigit1" androID:layout_wIDth="70dp" androID:layout_height="wrap_content" androID:textSize="80dp" androID:textAlignment="center" androID:gravity="center_horizontal" androID:hint="*" androID:textcolorHint="@color/french_gray" androID:backgroundTint="@color/french_gray" androID:FontFamily="sans-serif" androID:textcolor="@color/perfume" androID:maxLength="1" androID:inputType="number" />
当用户输入错误的号码时,我只想擦除并重新聚焦.注意:当你填写所有字段时,你会看到你可以删除并返回,但我想回到密码的中间位置.谢谢.
etCurrent.setonKeyListener(new VIEw.OnKeyListener() { @OverrIDe public boolean onKey(VIEw v,int keyCode,KeyEvent event) { if(etCurrent.getText().toString() == "" && keyCode == event.KEYCODE_DEL) { etCurrent.setText(""); etCurrent.clearFocus(); etBack.requestFocus(); etBack.setText(""); } return false; } });
当我触摸退格键时,我的Backspace侦听器不会触发,但会触发所有其他字符.
解决方法 这适用于我的4位密码活动.private voID setupinputListeners() { verificationCode1EditText.addTextChangedListener(new TextWatcher() { @OverrIDe public voID beforeTextChanged(CharSequence s,int count) { if (s.length() == 1) { verificationCode2EditText.requestFocus(VIEw.FOCUS_DOWN); } } @OverrIDe public voID afterTextChanged(Editable s) { } }); verificationCode2EditText.addTextChangedListener(new TextWatcher() { @OverrIDe public voID beforeTextChanged(CharSequence s,int count) { if(count == 0) { verificationCode1EditText.requestFocus(VIEw.FOCUS_DOWN); } else { if (s.length() == 1) { verificationCode3EditText.requestFocus(VIEw.FOCUS_DOWN); } } } @OverrIDe public voID afterTextChanged(Editable s) { } }); verificationCode3EditText.addTextChangedListener(new TextWatcher() { @OverrIDe public voID beforeTextChanged(CharSequence s,int count) { if(count == 0) { verificationCode2EditText.requestFocus(VIEw.FOCUS_DOWN); } else { if (s.length() == 1) { verificationCode4EditText.requestFocus(VIEw.FOCUS_DOWN); } } } @OverrIDe public voID afterTextChanged(Editable s) { } }); verificationCode4EditText.addTextChangedListener(new TextWatcher() { @OverrIDe public voID beforeTextChanged(CharSequence s,int count) { if(count == 0) { verificationCode3EditText.requestFocus(VIEw.FOCUS_DOWN); } } @OverrIDe public voID afterTextChanged(Editable s) { } });}总结
以上是内存溢出为你收集整理的Android如何在单击退格时关注另一个edittext全部内容,希望文章能够帮你解决Android如何在单击退格时关注另一个edittext所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)