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
- El salto de línea en Android agrega relleno
- Android Html.fromHtml función automática convierte texto no deseado en hipervínculos
- Actualización de Android TextView en subprocesos y ejecución
- ¿Cómo añadir sombra en el texto personalizado?
- Cómo hacer un script Mongolian tradicional TextView en Android
- HTML.fromHtml Saltos de línea que desaparecen
- Cómo ajustar texto a la siguiente línea en un Android TextView?
- EditText Alternativas en un Widget? Tiene que haber una forma
- Cómo se desvaneció un carácter único en un TextView
- El botón de clic no cambia el valor de vista de texto
- TextView FontSize según diferentes resoluciones y ScreenSize
- Superposición de texto sobre imageview en framelayout mediante programación - Android
- Android deshabilitar evento onclick cuando los vínculos de url hicieron clic
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 agregar un fragmento a un diseño de un DialogFragment?
- nueva línea cuando se utiliza DataOutputStream, Android