简体   繁体   中英

Maybe need something other than onClick

here a snippet from one of the layouts in my ViewPager.

<android.support.design.widget.TextInputLayout
        android:layout_width="286dp"
        android:layout_height="wrap_content"
        android:id="@+id/textInputLayout2"
        android:layout_marginTop="15dp"
        android:weightSum="1">

        <EditText
            android:id="@+id/email"
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_email"
            android:inputType="textEmailAddress"
            android:singleLine="true"
            android:textColor="@android:color/white"/>

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="286dp"
        android:layout_height="wrap_content"
        android:id="@+id/textInputLayout"
        android:layout_marginTop="15dp"
        android:weightSum="1">

        <EditText
            android:id="@+id/password"
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_password"
            android:inputType="textPassword"
            android:singleLine="true"
            android:textColor="@android:color/white"
            android:onClick="layoutBuilt"/>

    </android.support.design.widget.TextInputLayout>

And here is the layoutBuild void:

public void layoutBuilt(View view) {
        inputEmail = (EditText) findViewById(R.id.email);
        inputPassword = (EditText) findViewById(R.id.password);
        inputPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    //ACTION DONE
                }
                return false;
            }
        });
}

So my Problem is, that the User must click two times at the Done Button, that it works.

NOTE: It works when I click on the passowordEditText manually and than click Done. When I am clicking on the EmailEditText type in my Email and click Next the passowordEditText will be automatically selected. And when I type in password and click Done. That doesnt work.

Why and how to fix it? Thanks in advance.

Set the android:imeOptions to both of your `EditText.

<android.support.design.widget.TextInputLayout
    android:layout_width="286dp"
    android:layout_height="wrap_content"
    android:id="@+id/textInputLayout2"
    android:layout_marginTop="15dp"
    android:weightSum="1">

    <EditText
        android:id="@+id/email"
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_email"
        android:inputType="textEmailAddress"
        android:singleLine="true"
        android:imeOptions="actionNext"
        android:textColor="@android:color/white"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_width="286dp"
    android:layout_height="wrap_content"
    android:id="@+id/textInputLayout"
    android:layout_marginTop="15dp"
    android:weightSum="1">

    <EditText
        android:id="@+id/password"
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_password"
        android:inputType="textPassword"
        android:imeOptions="actionDone"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:onClick="layoutBuilt"/>

</android.support.design.widget.TextInputLayout>

So I solved the Problem by myself.

But thanks to @ADM . The onClick won't be called first when the View gets called by Android himself. So I call the layoutBuilt from the ViewPageAdapter in instantiateItem where the new layout already is created.

But thanks for all.

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.

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