0

I have edittext where user will enter the message.So I want to display the message in Textview.Now I want in a textview in one line only 23 character should be displayed and the remaining text should be displayed in the next line in textview.How can this be achieved in Android.

user7144720
  • 101
  • 1
  • 2
  • 8

3 Answers3

1

@user7144720

get EditText text inside one String variable

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);
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
eLemEnt
  • 1,741
  • 14
  • 21
0

try this.

android:maxLines="2"
Yongho
  • 21
  • 5
0

Try this:

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

setText method:

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;
}
Komal12
  • 3,340
  • 4
  • 16
  • 25