I read a multiline text from a .txt file, then I setText, but all linefeeds are gone, what am I missing? ( editor has android:inputType="textMultiLine" set):
BufferedReader r;
r = new BufferedReader(new FileReader(AbrarFilePaths.NotebooksPath() + fileName));
StringBuilder total = new StringBuilder();
String line;
while((line = r.readLine()) != null)
{ total.append(line);}
editor.setText(total);
Try using:
while((line = r.readLine()) != null)
{ total.append(line + "\n");}
editor.setText(total);
And set MaxLines to 1000 for example. It worked for me.
I dont think EditText can detect New Line character. You might have to build a custom component to handle that
Set this property in your xml file android:maxLines=" 10" 10 lines in edittext.
or you can try
<EditText
android:id="@+id/msgText"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:layout_marginRight="10dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:inputType="textMultiLine"
android:layout_height="150dip"
android:gravity="top"
android:padding="5dip">
</EditText>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.