简体   繁体   中英

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. Currently I load text file of size 17KB. I don't think, that 17KB is terrible amount of text. Scrolling is fine, but when I focus EditText and start edit, it has delay/freezing for 4-5 seconds. The same happends when I leave EditText. I'm using API level 8. and here is my layout for 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 :

    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? Thank you Anton

Custom EditText will not solve the problem. Editing in EditText will become slower when the text content inside it become too large. Try to use WebView instead of 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 );

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.

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