简体   繁体   English

按下键盘上的Enter键后,如何将控制权从一种文本视图传递到另一种文本视图?

[英]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" />

试试看, EditBoxrequestFocus()您可以在单击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" ,因为它不适用于多行输入。

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. 使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.

相关问题 在一个TextView中按下Button后如何显示多个EditText输入? - How to display multiple EditText inputs after pressing Button in one TextView? 在TextView中按Enter时,单击按钮? - When pressing enter inside TextView, click button? 按下按钮后显示键盘 - Show keyboard after pressing a button 在Android中按下软键盘上的Enter键后,TextView变得可编辑 - TextView getting Editable on pressing enter on soft keyboard in android 按下删除按钮后,如何从输入到我的 textView 的数据库中删除值? - How to delete value from the database which is entered into my textView after pressing delete button? 如何在Android中的自定义列表视图中按删除按钮后显示文本视图 - How to show textview after pressing delete button in custom Listview in android 当浏览器中的任何一种类型像往常一样用作Enter时,如何使键盘输入按钮说“搜索”? - How to make keyboard enter button say “Search” when any one type in browser other wise it used as Enter as usual? 单击按钮后如何将 integer 值从一个 java 文件传递到其他 java 文件 - How to pass integer vales from one java file to other java file after clicking button 按下返回按钮后隐藏Android键盘 - Hiding Android Keyboard after Pressing Back Button 按下按钮后android隐藏键盘 - android hide keyboard after pressing button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM