2017-04-13 9 views
0

私は線形レイアウトでedittextを動的に追加します。最初の編集テキストの編集を開始してキーボードの次のボタンを押すと、2番目の編集テキストに行くのではなく、最後のテキストにフォーカスが移動します。ここに私のアクティビティコードがあります。動的に追加されたEditTextsフォーカスは、キーボードの次のボタンがクリックされたときに最初から最後に移動します。

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

アクティビティは単なるリニアレイアウトです。そして、私は

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

答えて

0
にIDを設定することができ、また

editText.setNextFocusForwardId(R.id.secondView); 

次の焦点のために行くために定義する必要があります

このようにして解決しました

editText.setImeOptions(EditorInfo.IME_ACTION_NEXT); 
0

を膨張させるのですタブ項目のレイアウトは、あなたはどこでこのよう

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

私はedittextを動的に追加していますので、すべてのedittextに固有のIDはありません – user1401232

+0

あなたはview.setId()を使用できます。 –

関連する問題