I have two textViews shown below after pressing enter button in first textview the cursor should goes to second 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. You may need to specify android:singleLine="true"
, as this will not work on a multi-line input.
Documentation can be found here .
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.
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;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.