android 多个edittext的输入和删除
来源:互联网 发布:mac无法显示移动硬盘 编辑:程序博客网 时间:2024/05/29 16:58
在一个老同事的帮助下完成,感谢。页面部分:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background"> <include layout="@layout/top_org_info"/> <include layout="@layout/own_pieces_process"/> <TableRow android:layout_width="fill_parent" android:gravity="center"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:layout_marginBottom="100dip"> <TableRow android:layout_width="fill_parent"> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"> <TableRow> <!--<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" style="@style/title_text"/> <EditText android:id="@+id/own_pieces_captcha" android:layout_width="360dp" android:layout_height="wrap_content" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="6"/> </LinearLayout>--> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="六位取货密码:" style="@style/title_text"/> <EditText android:id="@+id/own_pieces_captcha_one" android:layout_width="43dp" android:layout_height="wrap_content" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:gravity="center" android:lines="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:textSize="31sp" > </EditText> <EditText android:id="@+id/own_pieces_captcha_two" android:layout_width="43dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:gravity="center" android:textSize="31sp" /> <EditText android:id="@+id/own_pieces_captcha_three" android:layout_width="42dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:gravity="center" android:textSize="31sp" /> <EditText android:id="@+id/own_pieces_captcha_four" android:layout_width="43dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:gravity="center" android:textSize="31sp" /> <EditText android:id="@+id/own_pieces_captcha_five" android:layout_width="43dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:gravity="center" android:textSize="31sp" /> <EditText android:id="@+id/own_pieces_captcha_six" android:layout_width="43dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/white" android:cursorVisible="false" android:ems="1" android:numeric="integer" android:maxLines="1" android:singleLine="true" android:maxLength="1" android:gravity="center" android:textSize="31sp" /> <EditText android:id="@+id/own_pieces_captcha" android:layout_width="30dp" android:layout_height="wrap_content" android:visibility="gone" /> </LinearLayout> </TableRow> </TableLayout> </TableRow> </TableLayout> </RelativeLayout> </TableRow> <View style="@style/background_split_blue"/> <TextView android:layout_height="15dp"/></TableLayout>后台处理:
package com.ourangel.terminal.activity;import android.content.Intent;import android.os.Bundle;import android.text.*;import android.view.KeyEvent;import android.view.View;import android.widget.EditText;import android.widget.TextView;import com.ourangel.terminal.R;import com.ourangel.terminal.application.CustomApplication;/** * Created by xuwenqiang on 14-5-5. */public class OwnPiecesActivity extends CommonActivity implements TextWatcher, View.OnClickListener, View.OnFocusChangeListener, View.OnKeyListener { // 验证码文本输入框 private EditText captchaEditText, captchaEtOne, captchaEtTwo, captchaEtThree, captchaEtFour, captchaEtFive, captchaEtSix; // 手机后四位文本输入框 public static OwnPiecesActivity instance; private int editInt; @Override public void onCreate(Bundle savedInstanceState) { instance = this; super.onCreate(savedInstanceState); setContentView(R.layout.activity_own_pieces); CustomApplication.getInstance().addActivity(this); findView(); initWidget(); } void findView() { captchaEtOne = (EditText) findViewById(R.id.own_pieces_captcha_one); captchaEtTwo = (EditText) findViewById(R.id.own_pieces_captcha_two); captchaEtThree = (EditText) findViewById(R.id.own_pieces_captcha_three); captchaEtFour = (EditText) findViewById(R.id.own_pieces_captcha_four); captchaEtFive = (EditText) findViewById(R.id.own_pieces_captcha_five); captchaEtSix = (EditText) findViewById(R.id.own_pieces_captcha_six); captchaEditText = (EditText) findViewById(R.id.own_pieces_captcha); captchaEtOne.addTextChangedListener(this); captchaEtTwo.addTextChangedListener(this); captchaEtThree.addTextChangedListener(this); captchaEtFour.addTextChangedListener(this); captchaEtFive.addTextChangedListener(this); captchaEtSix.addTextChangedListener(this); captchaEtOne.setOnKeyListener(this); captchaEtTwo.setOnKeyListener(this); captchaEtThree.setOnKeyListener(this); captchaEtFour.setOnKeyListener(this); captchaEtFive.setOnKeyListener(this); captchaEtSix.setOnKeyListener(this); captchaEtOne.setOnFocusChangeListener(this); captchaEtTwo.setOnFocusChangeListener(this); captchaEtThree.setOnFocusChangeListener(this); captchaEtFour.setOnFocusChangeListener(this); captchaEtFive.setOnFocusChangeListener(this); captchaEtSix.setOnFocusChangeListener(this); } void initWidget() { displayOperateTime = (TextView) findViewById(R.id.textView_displayOperateTime); super.onDisplayOperateTime(this); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { switch (editInt) { case 1: if (s.toString().length() == 1) { captchaEtTwo.setFocusable(true); captchaEtTwo.requestFocus(); } break; case 2: if (s.toString().length() == 1) { captchaEtThree.setFocusable(true); captchaEtThree.requestFocus(); } break; case 3: if (s.toString().length() == 1) { captchaEtFour.setFocusable(true); captchaEtFour.requestFocus(); } break; case 4: if (s.toString().length() == 1) { captchaEtFive.setFocusable(true); captchaEtFive.requestFocus(); } break; case 5: if (s.toString().length() == 1) { captchaEtSix.setFocusable(true); captchaEtSix.requestFocus(); } break; case 6: break; default: break; } } @Override public void onClick(View v) { } @Override public void onFocusChange(View v, boolean hasFocus) { switch (v.getId()) { case R.id.own_pieces_captcha_one: if (hasFocus) { editInt = 1; captchaEtOne.setSelection(captchaEtOne.getText().toString().length()); } break; case R.id.own_pieces_captcha_two: if (hasFocus) { editInt = 2; captchaEtTwo.setSelection(captchaEtTwo.getText().toString().length()); } break; case R.id.own_pieces_captcha_three: if (hasFocus) { editInt = 3; captchaEtThree.setSelection(captchaEtThree.getText().toString().length()); } break; case R.id.own_pieces_captcha_four: if (hasFocus) { editInt = 4; captchaEtFour.setSelection(captchaEtFour.getText().toString().length()); } break; case R.id.own_pieces_captcha_five: if (hasFocus) { editInt = 5; captchaEtFive.setSelection(captchaEtFive.getText().toString().length()); } break; case R.id.own_pieces_captcha_six: if (hasFocus) { editInt = 6; captchaEtSix.setSelection(captchaEtSix.getText().toString().length()); } break; default: break; } } @SuppressWarnings("static-access") @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (KeyEvent.KEYCODE_DEL == event.getKeyCode() && event.getAction() == event.ACTION_DOWN) switch (editInt) { case 1: break; case 2: captchaEtOne.setFocusable(true); captchaEtOne.requestFocus(); break; case 3: captchaEtTwo.setFocusable(true); captchaEtTwo.requestFocus(); break; case 4: captchaEtThree.setFocusable(true); captchaEtThree.requestFocus(); break; case 5: captchaEtFour.setFocusable(true); captchaEtFour.requestFocus(); break; case 6: captchaEtFive.setFocusable(true); captchaEtFive.requestFocus(); break; default: break; } return false; }}
0 0
- android 多个edittext的输入和删除
- android EditText 只能输入无法删除的解决方法
- Android-EditText只能输入不能删除的问题
- Android-EditText只能输入不能删除的问题
- Android自定义带删除按钮的输入框EditText
- Android EditText只能输入不能删除和清空输入内容
- android - EditText监听输入多少个字符
- Android模仿软键盘实现软键盘的删除功能(逐个删除EditText的输入元素)
- Android模仿软键盘实现软键盘的删除功能(逐个删除EditText的输入元素)
- EditText输入后不能删除的问题
- Android--过滤EditText的输入
- android TextWatcher 监听textview和edittext的文字输入改变
- Android EditText 限制文本框输入的长度和提示信息
- Android文本输入框EditText的属性和方法
- android 多个EditText光标的问题
- Android带删除的EditText
- Android自定义View-带删除和搜索图标的EditText
- Android打造带删除的EditText并且实现输入框密码显示、隐藏
- java中的匿名内部类总结
- 设置Dialog
- hdu 1379 DNA Sorting
- 文件关联后vb.net 软件如何响应被关联文件的双击事件
- 环形缓冲区的实现原理
- android 多个edittext的输入和删除
- Android中Canvas中drawPath或drawTextOnPath画不出来bug总结
- ACM - 归并排序
- 和菜鸟一起学OK6410之tftp下载内核,nfs挂载文件系统全过程详解
- 结构体的访问
- Android百度地图使用之定位和地理、反地理编码<基于定位SDK4.2>
- Android中实现如win7里边屏幕保护图案中三维文字的效果。
- securecrt中vim行号下划线问题
- macos java开发环境配置