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)
Android Studio:EditText editable is deprecated How to use inputType.
↳ 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 .
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With