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.
Asked
Active
Viewed 200 times
0
-
Your TextView should support multines and when writting text into it use \n for a new line. – David Kasabji Apr 06 '17 at 07:27
-
1set the android:maxLines = 2 and adjust the size of your textview – Ezio Apr 06 '17 at 07:27
-
you can use \n after completing your 23 characters in textview , so it will automatically start from the new line. – Rajshree Tiwari Apr 06 '17 at 07:30
-
Check this answer: http://stackoverflow.com/questions/21364923/android-limit-of-10-characters-per-line-textview – rafsanahmad007 Apr 06 '17 at 07:41
-
refer https://github.com/grantland/android-autofittextview – Krish Apr 06 '17 at 08:10
3 Answers
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:
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