[英]setting multiline text on Android EditText widget
I read a multiline text from a .txt file, then I setText, but all linefeeds are gone, what am I missing? 我从.txt文件中读取了多行文本,然后又设置了setText,但是所有换行都不见了,我还缺少什么? ( editor has android:inputType="textMultiLine" set):
(编辑器已设置android:inputType =“ textMultiLine”):
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. 并将MaxLines设置为1000。 It worked for me.
它为我工作。
I dont think EditText can detect New Line character. 我不认为EditText可以检测到换行符。 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. 在您的xml文件android:maxLines =“ 10” 10行的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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.