本文介绍了机器人:每行TextView的10个字符的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从我读的EditText值,并将其写入的TextView
I read value from EditText and write it to 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);
}
});
和我想,在一个行 - 最多10个字符,因此,如果所有的20个字符 - 这两个线路在TextView中,每行10个字符。我怎样才能做到这一点?
我尝试安卓:最大长度=10,但它并不能帮助
And I want that in one line - maximum 10 characters, so if all 20 characters - it's two line in TextView with 10 chars per line. How I can do this?I try android:maxLength="10" but it does not help
推荐答案
定义返回格式的有10个字符的字符串的方法每行:
Define a method that returns a string formatted to have 10 characters per line:
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;
}
这篇关于机器人:每行TextView的10个字符的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!