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" 
  • ¿Cómo hacer la escritura de texto de animación?
  • Selección del elemento de menú desbordamiento en TextView CustomActionModeCallback
  • Cómo insertar texto extraíble
  • ¿Cómo puedo escribir en un archivo .txt en Android?
  • Usando onClick en TextView con texto seleccionable - cómo evitar doble clic?
  • Estilo de texto de Android falta de luz, medio, delgado,
  • ¿Cómo puedo mostrar el último texto añadido en textview?
  • Ver contenido a continuación ExpandableListView
  • Escala de texto en una vista para que se ajuste?
  • ¿Cómo puedo interactuar con el diseño de Lockscreen para mostrar texto en él, como esta aplicación:
  • Cómo configurar la fuente personalizada para palabra en un texto TextView
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.