android: límite de 10 caracteres por línea TextView

He leído el valor de EditText y lo escribo en TextView

editTitle1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { s = editTitle1.getText().toString(); textTitle1.setText(s); } }); 

Y quiero que en una línea – máximo 10 caracteres, por lo que si los 20 caracteres – es dos línea en TextView con 10 caracteres por línea. ¿Como puedo hacer esto? Intento android: maxLength = "10" pero no ayuda

Defina un método que devuelve una cadena formateada para tener 10 caracteres por línea:

 public String getTenCharPerLineString(String text){ String tenCharPerLineString = ""; while (text.length() > 10) { String buffer = text.substring(0, 10); tenCharPerLineString = tenCharPerLineString + buffer + "/n"; text = text.substring(10); } tenCharPerLineString = tenCharPerLineString + text.substring(0); return tenCharPerLineString; } 

He editado la respuesta dada por ramaral que utilizó secuencia de escape mal

 public String getTenCharPerLineString(String text){ String tenCharPerLineString = ""; while (text.length() > 10) { String buffer = text.substring(0, 10); tenCharPerLineString = tenCharPerLineString + buffer + "\n"; text = text.substring(10); } tenCharPerLineString = tenCharPerLineString + text.substring(0); return tenCharPerLineString; } 

Agregue los siguientes 2 atributos a la definición de TextView:

 android:singleLine="false" android:maxems="10" 
  • Prensa larga sobre el texto seleccionado en textview en android
  • TextView con diferentes textSize
  • TextView ampliar animación como en Android Market
  • Añadir dinámicamente una vista al diseño de la actividad
  • ¿Por qué obtengo NullPointerException cuando uso setCurrentText o setText para TextSwitcher?
  • Cómo obtener las coordenadas XY y el tamaño de píxeles de un TextView?
  • Android: TextView: elimina el espaciado y el relleno en la parte superior e inferior
  • No inserte texto en Android TextView en el período en abreviatura
  • Android ScrollView scrollTo () método no funciona con TextView?
  • Disposición de Android: Envuelva dos vistas de texto
  • Android - ¿Espacio entre TextView y Togglebutton?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.