[英]How to pass control from one textview to other after pressing the enter button in keyboard?
I have two textViews shown below after pressing enter button in first textview the cursor should goes to second textview. 在第一个textview中按Enter键后,我有以下所示的两个textViews,光标应转到第二个textview。 How? 怎么样?
<AutoCompleteTextView
android:id="@+id/txt_login_username"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_above="@+id/pengala_logo"
android:layout_alignLeft="@+id/txt_login_pwd"
android:ems="10"
android:hint="Please enter Email"
android:inputType="textAutoComplete"
android:textColorHint="#ffffff"
android:textSize="20sp" />
<requestFocus />
<EditText
android:id="@+id/txt_login_pwd"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_alignLeft="@+id/btn_login_submit"
android:layout_alignTop="@+id/text"
android:ems="10"
android:hint="Please enter Password"
android:inputType="textPassword"
android:textColorHint="#ffffff"
android:textSize="20sp" />
试试看, EditBox
有requestFocus()
您可以在单击Button
同时使用它。
EditText.requestFocus();
Looking at this question , you can simply use the android:imeOptions="actionNext"
option on your txt_login_username
to change the 'enter' key to go to the 'next' input. 望着这个问题 ,你可以简单地使用android:imeOptions="actionNext"
你的选项txt_login_username
改变“ENTER”键进入“下一步”输入。 You may need to specify android:singleLine="true"
, as this will not work on a multi-line input. 您可能需要指定android:singleLine="true"
,因为它不适用于多行输入。
I think it should work 我认为应该可以
EditText editText1=(EditText)findViewById(R.id.text1);
EditText editTtext2=(EditText)findViewById(R.id.text2);
editText1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
editTtext2.requestFocus();
}
return true;
}
});
Make editText1 single line true. 使editText1单行为真。
final EditText editText = (EditText) findViewById(R.id.editText1);
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v , int keyCode , KeyEvent event) {
EditText editText2 = (EditText) findViewById(R.id.editText2);
// TODO Auto-generated method stub
if (keyCode == event.KEYCODE_A) {
Selection.setSelection((Editable) editText2.getText(),editText.getSelectionStart());
editText2.requestFocus();
}
return true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.