Dla*_*adu 11 android focus android-edittext
我有一个用户名和密码XML段
<EditText
android:id="@+id/username"
android:hint="@string/username_hint"
android:layout_width="match_parent"
android:maxLength="9"
android:nextFocusDown="@+id/pswd"
android:layout_height="wrap_content">
</EditText>
<EditText
android:inputType="textPassword"
android:hint="@string/password_hint"
android:id="@+id/pswd"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</EditText>
Run Code Online (Sandbox Code Playgroud)
我希望当用户名字段到达第9个字符时,光标焦点会自动跳转到密码字段
我正在自动查看Focus next textview并尝试:
final EditText usr = (EditText) findViewById (R.id.username);
final EditText pswd = (EditText) findViewById (R.id.pswd);
usr.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() == 9) {
pswd.requestFocus();
}
}
@Override
public void afterTextChanged(Editable arg0) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
});
Run Code Online (Sandbox Code Playgroud)
没有多大成功.我在我oncreate处理登录信息的方法中使用它.任何想法或建议将不胜感激.
小智 0
"s"把你的东西打印出来log.d(),这样你就可以看到它的样子"s"。
也许这不是你所期望的那样。
在这种情况下你可以code it dirty。
自己制作一个实现 TextWatcher 的TextWatcher组件,并在构造函数中给出. 这样你就可以得到总长度"usr"usr.getText()
| 归档时间: |
|
| 查看次数: |
7320 次 |
| 最近记录: |