2017-12-31 126 views
0

hier ein Ausschnitt aus einem der Layouts in meinem ViewPager.Vielleicht brauche etwas anderes als onClick

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

Und hier ist die layoutBuild Leere:

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; 
      } 
     }); 
} 

Also mein Problem ist, dass der Benutzer zwei Mal auf die Schaltfläche Fertig klicken muss, dass es funktioniert.

HINWEIS: Es funktioniert, wenn ich manuell auf den PassowordEditText klicke und dann auf Fertig klicke. Wenn ich in meiner E-Mail auf den Typ EmailEditText klicke und auf Weiter klicke, wird automatisch der passowordEditText ausgewählt. Und wenn ich ein Passwort eintippe und auf Fertig klicke. Das funktioniert nicht.

Warum und wie es zu beheben? Vielen Dank im Voraus.

Antwort

0

Also löste ich das Problem selbst.

Aber dank @ADM. Der onClick wird nicht zuerst aufgerufen, wenn der View von Android selbst aufgerufen wird. Also rufe ich das layoutBuilt vom ViewPageAdapter in instantiateItem auf, wo das neue Layout bereits erstellt wird.

Aber danke für alle.

+1

Danke ADM mit Plus 1, nicht schreiben "Danke". Sie werden dadurch nicht weniger reich werden - im Gegenteil, Sie werden reicher beim Erkennen. Freundlichkeit bringt Freundlichkeit. Frohes neues Jahr. Willkommen bei StackOverflow. – statosdotcom

0

Setzen Sie die android:imeOptions auf beide Ihrer `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> 
+0

@marcelo Korrigieren Sie mich, wenn ich die Frage missverstanden habe. Thx – ADM

Verwandte Themen