简体   繁体   English

Android EditText和大量文本

[英]Android EditText and large amount of text

I work on some application with ability to edit text files. 我在一些能够编辑文本文件的应用程序上工作。 But I have serious problem with EditText. 但是我对EditText存在严重问题。 Currently I load text file of size 17KB. 目前我加载大小为17KB的文本文件。 I don't think, that 17KB is terrible amount of text. 我不认为,17KB是可怕的文本量。 Scrolling is fine, but when I focus EditText and start edit, it has delay/freezing for 4-5 seconds. 滚动很好,但是当我关注EditText并开始编辑时,它会延迟/冻结4-5秒。 The same happends when I leave EditText. 当我离开EditText时也会发生同样的事情。 I'm using API level 8. and here is my layout for edittext : 我正在使用API​​级别8.这是我的edittext布局:

    <EditText android:id="@+id/journal_text"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:gravity="top|left"
                android:layout_weight="1"
                android:lines="20"
                android:inputType="textMultiLine|textNoSuggestions"
                android:scrollbars="vertical"
                android:fadeScrollbars="false"
                >

                <requestFocus />

            </EditText>

Here is my java code : 这是我的java代码:

    edit = (EditText)view.findViewById(R.id.journal_text);
    edit.setText(readFile(path));   

that's all 就这样

From GooglePlay I've downloaded app Jota text editor and it works perfectly with large text data...Can anyone help me please or direct me how to solve this problem? 来自GooglePlay我已经下载了应用程序Jota文本编辑器,它可以很好地处理大型文本数据......任何人都可以帮助我或指导我如何解决这个问题? Thank you Anton 谢谢安东

Custom EditText will not solve the problem. 自定义EditText无法解决问题。 Editing in EditText will become slower when the text content inside it become too large. 当EditText中的文本内容变得太大时,EditText中的编辑将变得更慢。 Try to use WebView instead of EditText. 尝试使用WebView而不是EditText。 It will perfectly work for a very large text content also. 它也适用于非常大的文本内容。

you have to use scanner to read text file. 你必须使用扫描仪来读取文本文件。

StringBuilder stringBuilder = new StringBuilder();
Scanner scanner = new Scanner(tempFile).useDelimiter("\\Z");
while (scanner.hasNext()) {
stringBuilder .append(scanner.next());
}

edit.setText(stringBuilder );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM