将下一个EditText设置为可在KEY_DOWN上聚焦并进行编辑 [英] Set next EditText focused and editable on KEY_DOWN
本文介绍了将下一个EditText设置为可在KEY_DOWN上聚焦并进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个editexts的布局.当在第一个上按下回车键时,我需要将第二个设置为焦点且可编辑.我有用于设置焦点的代码,但是当第二个焦点获得焦点时,我 无法开始输入 .
I've got a layout with two editexts. I need to set the second one focused and editable when the enter key is hit on the first one. I've got code for setting focus but I can't start typing when the second one gets the focus.
PS我还需要edittext恰好是一行的高度,而不能进行附加的行.它也可以正常工作. pss android 2.3
PS I also need edittext to be exactly one line height without possibility of making addtional rows. It works as well. pss android 2.3
XML代码:
<EditText
android:id="@+id/email"
style="@style/profileLoginInput"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/email" android:ems="10" android:lines="1" android:maxLines="1" android:ellipsize="end">
<requestFocus />
</EditText>
<EditText
android:id="@+id/password"
style="@style/profileLoginInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPassword" android:hint="@string/password">
Java代码:
((EditText) findViewById(R.id.email)).setOnKeyListener(new OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
((EditText) findViewById(R.id.password)).requestFocus();
return true;
default:
break;
}
}
return false;
}
});
推荐答案
在仿真器上运行此代码时,似乎有问题.但是,它可以在手机上使用
It seems to be bugged when running this code on the emulator. However, it works on phones
这篇关于将下一个EditText设置为可在KEY_DOWN上聚焦并进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文