Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText alternative

Currently, Android's EditText is extremely slow when dealing with a huge amount of lines of text (10000+). It appears like this slowdown is partially due to the fact that EditText supports spans, and primarily due to the fact that EditText is calculating the width of each line, which is very expensive. Are there any faster alternatives to EditText, or a way to optimize it to make it usable?

EDIT: Method traces are as follows:

android.text.StaticLayout.generate: 99.1% CPU time inclusive, 8.8% exclusive (1 call)
    android.text.Layout.getParagraphSpans: 28% inclusive, 1.1% exclusive (4686 calls)
    android.text.MeasuredText.setPara: 20.6% inclusive, 1.6% exclusive (2343 calls)
    android.text.MeasuredText.addStyleRun: 18.6% inclusive, 1.1& exclusive (2343 calls)
    android.text.SpannableStringBuilder.getSpans: 15% inclusive (of parent calls), 56.7% inclusive (of all calls, 47.3% of which are from android.text.Layout.getParagraphSpans, 26% are from android.text.MeasuredText.setPara, 26% are from android.text.StaticLayout.generate)
like image 699
Zambezi Avatar asked Apr 23 '15 14:04

Zambezi


People also ask

Is EditText deprecated?

Android Studio:EditText editable is deprecated How to use inputType.

What is TextInputEditText?

↳ com.google.android.material.textfield.TextInputEditText. A special sub-class of EditText designed for use as a child of TextInputLayout . Using this class allows us to display a hint in the IME when in 'extract' mode and provides accessibility support for TextInputLayout .

What is a TextInputLayout in android?

TextInputLayout is a view container that is used to add more features to an EditText. It acts as a wrapper for EditText and has some features like: Floating hint. Animation that can be disabled or enabled. Error labels that display error messages when an error occurs.

What is the difference between an EditText and a TextView?

EditText is used for user input. TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.


2 Answers

The best thing you can do is using RecyclerView with EditText as its item, so you get a new EditText for each of your lines.

New line will be the only thing you will have to implement.

like image 68
Ilya Gazman Avatar answered Sep 19 '22 02:09

Ilya Gazman


Although this article only talks about optimizing static TextViews where the text doesn't change, it might get you on the right track for making a more performant EditText.

like image 42
Andrew Orobator Avatar answered Sep 19 '22 02:09

Andrew Orobator