2012-09-14 14 views
6

Quiero mover el cursor de EditText1 a otro EditText2. Ya me había centrado en editText1 pero cómo mover el cursor a editText2.?Android Mueva el cursor de Editar texto a otro si hace clic en cualquier letra en el campo?

+0

tal vez añadir un [TextWatcher] (http://developer.android.com/reference/android/text/TextWatcher.html) en su 'EditText1' – Aprian

+0

ver mi respuesta aquí: http: //stackoverflow.com/questions/9003166/android-keyboard-next-button-issue-on-edittext/9003285#9003285 Podría ayudar. – Hiral

+0

Gracias a ti (Aprian and Hiral) por tu ayuda. Ahora funciona, TextWatcher me ayuda ..... – anoop

Respuesta

0

las propiedades establecidas en el código de edittext1 clic ...

EditText2.requestFocus();

0
EditText editText1 = (EditText)findViewById(R.id.editText1); 
    EditText editText2 = (EditText)findViewById(R.id.editText2); 


editText1.setOnKeyListener(new OnKeyListener() { 

public boolean onKey(View v, int keyCode, KeyEvent event) { 
     // If the event is a key-down event on the "enter" button 
     if ((event.getAction() == KeyEvent.ACTION_DOWN) && 
      (keyCode == KeyEvent.KEYCODE_ENTER)) 
     { 
      // Perform action on Enter key press 
      editText1.clearFocus(); 
      editText2.requestFocus(); 
      return true; 
     } 
     return false; 
} 
}); 
10

Finaly Tengo la respuesta:

editText1.addTextChangedListener(new TextWatcher() { 

       public void onTextChanged(CharSequence s, int start, int before, 
         int count) { 
        Integer textlength1 = editText1.getText().length(); 

        if (textlength1 >= 1) { 
         editText2.requestFocus(); 
        } 
       } 

       @Override 
       public void afterTextChanged(Editable s) { 
        // TODO Auto-generated method stub 
       } 

       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, 
         int after) { 
        // TODO Auto-generated method stub 
       } 
      }); 

      editText2.addTextChangedListener(new TextWatcher() { 

       public void onTextChanged(CharSequence s, int start, int before, 
         int count) { 
        Integer textlength2 = editText1.getText().length(); 

        if (textlength2 >= 1) { 
         editText3.requestFocus(); 

        } 
       } 

       @Override 
       public void afterTextChanged(Editable s) { 
        // TODO Auto-generated method stub 
       } 

       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, 
         int after) { 
        // TODO Auto-generated method stub 

       } 
      }); 
2

Puedo entender su respuesta,

Pero hay otra buena manera de hacerlo simplemente utilizando el siguiente atributo

android: imeOptions = "actionNext"

El ejemplo:

<EditText 
android:hint="@string/hint_user_name" 
android:id="@+id/et_user_name" 
android:maxLines="2" 
style="@style/EditText_Login" 
android:imeOptions="actionNext" 
/> 

Gracias,

Cuestiones relacionadas