2017-04-13 1 views
0

Ich füge dynamisch edittext in einem linearen Layout hinzu. Wenn ich anfange, den ersten Bearbeitungstext zu bearbeiten, und dann die Weiter-Taste auf der Tastatur drücke, geht der Fokus auf den letzten und nicht auf den zweiten. Hier ist mein Aktivitätscode ..Dynamisch hinzugefügter EditTexts-Fokus geht vom ersten zum letzten, wenn auf die Schaltfläche neben der nächsten Schaltfläche geklickt wird

LinearLayout layout =(LinearLayout) findViewById(R.id.activity_main); 
for (int i = 0; i < 3; i++) { 
     final View childView = this.getLayoutInflater().inflate(R.layout.tabitem, null); 
     TextView questionText = (TextView) childView.findViewById(R.id.questionId); 
     EditText editText = (EditText) childView.findViewById(R.id.enterAnswerTextId); 

     questionText.setText("Whats up"); 
     layout.addView(childView); 
     childView.setTag(i); 
    } 

Aktivität ist nur ein lineares Layout. Und die Registerkarte Element Layout, das ich Aufblasen am

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:id="@+id/separatorId" 
    android:orientation="horizontal" 
    android:layout_height="1dp" 
    /> 

<TextView 
    android:layout_width="wrap_content" 
    android:id="@+id/questionId" 
    android:layout_height="wrap_content" 
    android:paddingLeft="20dp" 
    android:paddingTop="20dp" 
    android:paddingBottom="15dp" 
    /> 

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

    <EditText 
     android:id="@+id/enterAnswerTextId" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="20dp" 
     android:layout_marginLeft="20dp" 
     android:maxLines="1" 
     android:layout_centerHorizontal="true" 
     android:inputType="textPassword" 
     android:hint="Enter Answer" 
     android:padding="20dp" 
     android:imeOptions="actionNext|actionDone"/> 

</RelativeLayout> 

Antwort

0

sollten Sie definieren, wo für den nächsten Fokus gehen

editText.setNextFocusForwardId(R.id.secondView); 

auch Sie id auf diese Weise

view.setId(/*some unique integer as id*/) 
+0

Ich füge edittext dynamisch hinzu, so dass es keine eindeutigen IDs für alle edittext gibt – user1401232

+0

Sie können view.setId(); –

Verwandte Themen