简体   繁体   English

使用包含标签时的键盘下一个按钮

[英]Keyboard next button when using include tag

I have seen/tried the following questions, but mine is not the same:我已经看到/尝试过以下问题,但我的不一样:


First, I have a CardView wherein I have a EditText , like below:首先,我有一个CardView其中有一个EditText ,如下所示:

<RelativeLayout
    android:id="@+id/topCard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/myCard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"           
        android:clickable="false"
        android:foreground="?android:attr/selectableItemBackground"
        android:orientation="horizontal"
        app:cardCornerRadius="5dp"
        app:cardElevation="3dp"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="#26c2ef">

        </RelativeLayout>


        <RelativeLayout
            android:id="@+id/cardTopTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="5dp">


            <TextView
                android:id="@+id/lessonTitleHeading"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:text="Please provide a name:"
                android:textColor="#000000"
                android:textSize="18sp" />

            <ImageView
                android:id="@+id/horiLine"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/lessonTitleHeading"
                android:layout_marginEnd="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginStart="10dp"
                android:background="#60000000" />

            <EditText
                android:id="@+id/noteEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/horiLine"
                android:layout_marginEnd="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="5dp"
                android:background="@android:color/transparent"
                android:hint="Enter name here..."
                android:imeOptions="actionNext" />


        </RelativeLayout>


    </android.support.v7.widget.CardView>


</RelativeLayout>

I then inflate this layout in another by using include like this:然后我通过使用这样的include在另一个布局中膨胀这个布局:

<include
    android:id="@+id/lessonTitle"
    layout="@layout/activity_notes_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

and in my Activity class I do the following:在我的 Activity 类中,我执行以下操作:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_leason);

    View tvOne = findViewById(R.id.tvOne);
    View tvTwo = findViewById(R.id.tvTwo);
    View tvThree = findViewById(R.id.tvThree);
    View tvFour = findViewById(R.id.tvFour);

    final TextView tvOne = (TextView)vLessonTitle.findViewById(R.id.lessonTitleHeading);
    final EditText etOne = (EditText) vLessonTitle.findViewById(R.id.noteEditText);

    TextView tvTwo = (TextView)vlessonProbStu.findViewById(R.id.lessonTitleHeading);
    final EditText etTwo = (EditText) vlessonProbStu.findViewById(R.id.noteEditText);

    TextView tvThree = (TextView)vLessonWorkedOn.findViewById(R.id.lessonTitleHeading);
    final EditText etThree = (EditText) vLessonWorkedOn.findViewById(R.id.noteEditText);

    TextView tvFour = (TextView)vlessonWhatStudShouldWorkOn.findViewById(R.id.lessonTitleHeading);
    final EditText etFour = (EditText)vlessonWhatStudShouldWorkOn.findViewById(R.id.noteEditText);

    tvOne.setText("This is the first CardView:");
    etOne.setHint("Enter Title Here...");

    tvTwo.setText("This is the second CardView:");
    etTwo.setHint("Enter Text Here...");

    tvThree.setText("This is the third CardView:");
    etThree.setHint("Enter Text Here...");

    tvFour.setText("This is the fourth CardView:");
    etFour.setHint("Enter Text Here...");

    //I tried this, but it didn't work...
    etOne.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER))
            {
                // Perform action on Enter key press
                etLessonTitle.clearFocus();
                etLessonProbStu.requestFocus();
                return true;
            }
            return false;
        }
    });

}

The Layout now looks like this:布局现在看起来像这样:

最终布局

At this point I have a bunch of CardView s with EditText s underneath each other like above.在这一点上,我有一堆CardView s 和EditText s 像上面一样彼此下方。 I would like to use the next button in the keyboard to go to the next CardsView s EditText .我想使用键盘中的下一个按钮转到下一个CardsViewEditText

If you have a look at my Activity class above, I tried using setOnKeyListener and clearFocus from the current EditText then requestFocus on the next EditText , but that didn't work.如果您查看我上面的 Activity 类,我尝试从当前EditText使用setOnKeyListenerclearFocus然后在下一个EditText上使用requestFocus ,但这没有用。

Any ideas how I can achieve this?任何想法如何实现这一目标?

Try this you need to set android:inputType="" to your Editext with android:imeOptions="actionNext"试试这个,你需要使用android:imeOptions="actionNext"android:inputType=""为你的Editext

<EditText
    android:id="@+id/noteEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/horiLine"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="5dp"
    android:background="@android:color/transparent"
    android:hint="Enter name here..."
    android:inputType="text" // specifies your input type here  
    android:imeOptions="actionNext" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM