2011-02-02 2 views
2

私は既にこれを検索しましたが、解決策は見つかりませんでした。ここでは、私はedittext1とedittext2を持っていますが、carat/cursorはedittext1に配置されていますが、ソフトキーボードの "Next/Enter"キーを押すと、carat/cursorはedittext2に配置する必要があります。次のスニペットは、「次へ/入力」キーを押したが、edittext2のカラット/カーソルを移動しなかったときにイベントを受け取った。edittext1からedittext2へのカラット/カーソルの設定

edittext1.setOnKeyListener(new View.OnKeyListener() 
    {  
     @Override 
     public boolean onKey(View v, int keyCode, KeyEvent event) 
     { 
      if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER) 
      { 
       Editable e = edittext2.getText(); 
       Selection.setSelection(e,e.length()); 
      } 
      return false; 
     } 
    }); 

いずれの入力も高く評価されます。ありがとう。

答えて

1

imeOptionsセットを持っているということですif(event.getKeyCode()== KeyEvent.KEYCODE_ENTER) { edittext2.requestFocus();
}

カーソルがedittext2に移動します。

+0

ありがとうございました。完璧に働いています。 – exception01

+0

嬉しいです。私のポストへの "投票アップ"は正常に受け入れられるでしょう;) – user599814

3

XMLでandroid:nextFocusDownandroid:nextFocusUpを使用することはできませんか?ここではいくつかの参照は、次のとおりです。

EDIT
あなたの受け入れ答えを使用すると、機能するソリューションを持っているように見えます、しかし、私はXMLを取得したいと思いました仕事に行く道も。だからここにあなたのレイアウト要素の作業バージョンです: :

<AutoCompleteTextView 
    android:id="@+id/autoCompleteTextViewRecipient" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:completionThreshold="1" 
    android:inputType="text" 
    android:maxLines="1" 
    android:hint="To" 
    android:imeOptions="actionNext" 
    android:nextFocusDown="@+id/editTextComposeMessage" 
    android:nextFocusUp="@+id/editTextComposeMessage"/> 
<EditText 
    android:id="@+id/editTextComposeMessage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:imeOptions="actionNext" 
    android:nextFocusDown="@+id/autoCompleteTextViewRecipient" 
    android:nextFocusUp="@+id/autoCompleteTextViewRecipient"/> 

違いはAutoCompleteTextViewが今nextFocusDownを持っている、EditTextnextFocusUpを持っている、との両方がこれを使用してみてくださいactionNext

+0

それでもそれは動作しませんでした... \t \t <のEditText android:id = "@ + id/editTextComposeMessage" android:layout_width = "wrap_content" android:layout_height = "wrap_content" androi d:nextFocusDown = "@ + id/autoCompleteTextViewRecipient" /> – exception01

+0

@exceptionあなたのXMLの動作中のバージョンで私の答えを更新しました –

関連する問題