2016-01-20 16 views
5

Mam obok siebie dwa elementy TextInputLayout: imię i nazwisko. Pod nimi mam inny element o pełnej szerokości TextInputLayout: email.TextInputLayout EditText nextFocusRight nie działa tak jak powinien

próbuję zastąpić następny przycisk na klawiaturze, tak aby po kliknięciu przycisku Dalej wewnątrz wejścia imię, należy przejść do lastName wejście, a stamtąd do wiadomości e-mail itd.

Teraz problemem jest to, że kiedy naciśniesz Dalej na klawiaturze, nie przejdę do pola nazwiska, ale zamiast tego przejdę pod adres e-mail poniżej.

To jest część mojego pliku xml, gdzie mam te trzy wejścia:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_gravity="center_horizontal" 
    android:baselineAligned="false"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/input_layout_firstname" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <EditText 
      android:id="@+id/register_input_firstname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/hint_firstname" 
      android:inputType="textCapSentences" 
      android:nextFocusForward="@+id/register_input_lastname" 
      android:nextFocusRight="@+id/register_input_lastname" /> 

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

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/input_layout_lastname" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <EditText 
      android:id="@+id/register_input_lastname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/hint_lastname" 
      android:inputType="textCapSentences" 
      android:nextFocusDown="@+id/register_input_email" /> 

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

</LinearLayout> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/input_layout_email" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:id="@+id/register_input_email" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/hint_email" 
     android:inputType="textEmailAddress" /> 

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

Próbowałem również kierowanie TextInputLayout zamiast EditText ale to nie ma znaczenia.

Czy następne ogniskowanie jest możliwe z TextInputLayout lub jest to błąd, czy robię coś bardzo nie tak?

+0

Jeśli odpowiedź @Yen Pei Tay nie ma go naprawić, spróbuj następujących. http://stackoverflow.com/a/41489258/1015678 –

Odpowiedz

6

Zmiana ta -> android: nextFocusDown = „@ + id/register_input_lastname”

+0

Haha, to faktycznie działa. Zgaduję, że przyczyną jest to, że ostrość w naturalny sposób przesuwa się w dół, a pod względem technicznym dane wejściowe z nazwiska są poniżej imienia. Ale nie rozumiem, dlaczego jest NextFocusRight itp? Czy te działają tylko na zwykłych wejściach EditText? –

+0

Nie mam pojęcia, ale warto spróbować. –

+0

Nie umieszczałem symbolu plusa, który powodował, że nie znalazł identyfikatora. dodanie plusa to dobry pomysł, dzięki. – j2emanue

3

Powyższa odpowiedź jest poprawna, ale po prostu trzeba coś dodać, gdy próbuję i nie dostać się skupić na następnym linia więc dodać jeszcze jeden atrybut w uzupełnieniu do powyższej odpowiedzi

android: „swĂłj wejście tutaj” InputType =

po włożeniu tego dostałem edytować tekst ostrość do następnego

przykład

android: InputType = "text" // ustawić dowolny typ wejścia jak na swoje wymagania

android: nextFocusDown = "@ + id/next_id"

Kompletna przykład z EditText

<android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
      android:textColorHint="@color/hint"> 

      <EditText          
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="1" 
       android:id="@id/first_name_edt" 
       android:nextFocusDown="@+id/last_name_edt" 
       android:imeOptions="actionNext" 
       android:inputType="text" 
       android:hint="@string/str_first_name" /> 
     </android.support.design.widget.TextInputLayout> 

nadzieję, że to pomoże innym :)

1

Kiedyś ten kod pod nim działa jak magiczny :)

Właściwie sztuką jest

android: imeOptions = "actionNext"

android: nextFocusDown = "@ + id/tilAddress"

android: InputType = "text"

<android.support.design.widget.TextInputLayout 
     android:id="@+id/tilSchoolName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/margin_small"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="@dimen/text_size_small" 
      android:textColor="@color/colorTxt" 
      android:maxLines="1" 
      android:imeOptions="actionNext" 
      android:nextFocusDown="@+id/tilAddress" 
      android:inputType="text" 
      android:hint="School Name" /> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/tilAddress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="@dimen/text_size_small" 
      android:textColor="@color/colorTxt" 
      android:maxLines="1" 
      android:hint="Address" /> 
    </android.support.design.widget.TextInputLayout> 
Powiązane problemy