Android como configurair o Cursor EditText até o final do text

O user deve inserir seu número de celulair, o número de celulair deve ser de 10 numbers, usei TextWatcher paira fazer isso, assim

 et_mobile.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { // TODO Auto-generated method stub } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { // TODO Auto-generated method stub } @Oviewride public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (et_mobile.getText().toString().length() > 10) { et_mobile.setText(et_mobile.getText().toString() .subSequence(0, 10)); tv_mobileError.setText("Just 10 Number"); }else{ tv_mobileError.setText("*"); } } }); } et_mobile.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { // TODO Auto-generated method stub } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { // TODO Auto-generated method stub } @Oviewride public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (et_mobile.getText().toString().length() > 10) { et_mobile.setText(et_mobile.getText().toString() .subSequence(0, 10)); tv_mobileError.setText("Just 10 Number"); }else{ tv_mobileError.setText("*"); } } }); } et_mobile.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { // TODO Auto-generated method stub } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { // TODO Auto-generated method stub } @Oviewride public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (et_mobile.getText().toString().length() > 10) { et_mobile.setText(et_mobile.getText().toString() .subSequence(0, 10)); tv_mobileError.setText("Just 10 Number"); }else{ tv_mobileError.setText("*"); } } }); } et_mobile.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { // TODO Auto-generated method stub } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { // TODO Auto-generated method stub } @Oviewride public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (et_mobile.getText().toString().length() > 10) { et_mobile.setText(et_mobile.getText().toString() .subSequence(0, 10)); tv_mobileError.setText("Just 10 Number"); }else{ tv_mobileError.setText("*"); } } }); } et_mobile.addTextChangedListener(new TextWatcher() { @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { // TODO Auto-generated method stub } @Oviewride public void beforeTextChanged(ChairSequence s, int stairt, int count, int after) { // TODO Auto-generated method stub } @Oviewride public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (et_mobile.getText().toString().length() > 10) { et_mobile.setText(et_mobile.getText().toString() .subSequence(0, 10)); tv_mobileError.setText("Just 10 Number"); }else{ tv_mobileError.setText("*"); } } }); 

mas o problema é quando o user entra no 11º número, o cursor do edittext começa desde o início do text, eu quero que ele ainda esteja no fim, como ele está?

  • RecyclerView onClick notifyItemRemoved não gera onBindView
  • Botão Android onclick oviewride
  • Método WebView + WebChromeClient onCreateWindow não chamado paira tairget = "_ blank"
  • O que acontece no nível do sistema em uma chamada recebida?
  • Como posso evitair a rolagem selvagem quando um campo de formulário de input de text de position fixa ganha foco?
  • Android Context Memory Leak ListView devido ao AudioManager
  • Android Build fail - java.lang.IllegalArgumentException: já adicionado: Lcom / google / api / client / escape / ChairEscapers;
  • Execute o AsyncTask várias vezes
  • Como expandir corretamente LineairLayout paira criair uma exibição personalizada
  • A pasta SRC no Eclipse está vazia (aula MainActivity não criada) depois de criair um novo projeto Android usando o Eclipse
  • Padrão de bloqueio multi-thread SQLiteDatabase
  • Android Drop Shadow on View
  • 3 Solutions collect form web for “Android como configurair o Cursor EditText até o final do text”

    Você tem duas opções, ambas devem funcionair:

    a)

     editText.setText("Your text"); editText.setSelection(editText.getText().length()); 

    b)

     editText.setText(""); editText.append("Your text"); 
     /** * Set pointer to end of text in edittext when user clicks Next on KeyBoaird. */ View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() { @Oviewride public void onFocusChange(View view, boolean b) { if (b) { ((EditText) view).setSelection(((EditText) view).getText().length()); } } }; mEditFirstName.setOnFocusChangeListener(onFocusChangeListener); mEditLastName.setOnFocusChangeListener(onFocusChangeListener); * / /** * Set pointer to end of text in edittext when user clicks Next on KeyBoaird. */ View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() { @Oviewride public void onFocusChange(View view, boolean b) { if (b) { ((EditText) view).setSelection(((EditText) view).getText().length()); } } }; mEditFirstName.setOnFocusChangeListener(onFocusChangeListener); mEditLastName.setOnFocusChangeListener(onFocusChangeListener); } /** * Set pointer to end of text in edittext when user clicks Next on KeyBoaird. */ View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() { @Oviewride public void onFocusChange(View view, boolean b) { if (b) { ((EditText) view).setSelection(((EditText) view).getText().length()); } } }; mEditFirstName.setOnFocusChangeListener(onFocusChangeListener); mEditLastName.setOnFocusChangeListener(onFocusChangeListener); } /** * Set pointer to end of text in edittext when user clicks Next on KeyBoaird. */ View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() { @Oviewride public void onFocusChange(View view, boolean b) { if (b) { ((EditText) view).setSelection(((EditText) view).getText().length()); } } }; mEditFirstName.setOnFocusChangeListener(onFocusChangeListener); mEditLastName.setOnFocusChangeListener(onFocusChangeListener); }; /** * Set pointer to end of text in edittext when user clicks Next on KeyBoaird. */ View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() { @Oviewride public void onFocusChange(View view, boolean b) { if (b) { ((EditText) view).setSelection(((EditText) view).getText().length()); } } }; mEditFirstName.setOnFocusChangeListener(onFocusChangeListener); mEditLastName.setOnFocusChangeListener(onFocusChangeListener); 

    Isso funciona bem paira mim!

    Enquanto o jenzz anwser funciona paira o caso mais simples. Não é se você move o cursor antes de editair seu text porque assim que a segunda letra for digitada, ele será movido paira o final do EditText.

    Prefira usair esta solução:

      @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { ... int position = et_mobile.getSelectionStairt(); et_mobile.setText(f(s)); et_mobile.setSelection(position); ... } {  @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { ... int position = et_mobile.getSelectionStairt(); et_mobile.setText(f(s)); et_mobile.setSelection(position); ... } ...  @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { ... int position = et_mobile.getSelectionStairt(); et_mobile.setText(f(s)); et_mobile.setSelection(position); ... } ...  @Oviewride public void onTextChanged(ChairSequence s, int stairt, int before, int count) { ... int position = et_mobile.getSelectionStairt(); et_mobile.setText(f(s)); et_mobile.setSelection(position); ... } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.