动态增加textview

时间:2017-04-06 07:25:42

标签: android textview

我有edittext用户将输入消息。所以我想在Textview中显示消息。现在我想在一行文本视图中只显示23个字符,其余文本应显示在下一行中textview。如何在Android中实现这一目标。

3 个答案:

答案 0 :(得分:1)

@ user7144720

EditText变量

中获取String个文字
String finalString = "";
String textToShow = sampleEditText.getText().toString();
if (textToShow.length > 23) {
    finalString = textToShow.substring(0,23) + "\n" + textToShow.substring(23);
}
else {
    finalString = textToShow;
}
//then set finalString for your textview

textViewDisplay.setText(finalString);

答案 1 :(得分:0)

试试这个。

android:maxLines="2"

答案 2 :(得分:0)

试试这个:

String your_data="abcdef......";
String value=setText(your_data);
textView.setText(value);

setText方法:

public String setText(String text){

    String lineString = "";
    while (text.length() > 23) {

        String buffer = text.substring(0, 23);
        lineString = lineString + buffer + "/n";
        text = text.substring(23);
    }

    lineString = lineString + text.substring(0);
    return lineString;
}