4

I'm writing a text editor similar to QuickEdit and Turbo Editor.

However, I faced the problem that when my EditText deals with a large amount of code lines, it becomes slower and lagging.

From this question I found out that in my case I should create a custom EditText, then from this and this I suggested that I should override onDraw() and onMeasure() methods in it, but I didn't understand how I can apply this to EditText, and not to TextView.

Reading the sources also didn't give me the answer: I didn't find lines that possibly could improve performance of custom EditText.

Long story short: I'm looking for a way and detailed explanations on how to optimize EditText for a large amount of code lines (10 000 <).

Sinomine
  • 41
  • 1
  • The issue is still pending. I faced the same problem. But one thing I'm surprised of is anWrite apk is faster even for huge amounts yet very small in size! – Francis Nduba Numbi May 17 '18 at 22:38

2 Answers2

2

TLDR: If you want to put a large amount of text in an EditText, make a custom View that inherits from the base EditText, and do not use AppCompatEditText!


Quite an old question, but I recently had a similar requirement myself (i.e. having an EditText with a huge amount of text), and stumbled on the solution.

The culprit is the androidx.appcompat library, which provides things like AppCompatEditText, which is a wrapper around the EditText platform class, and provides certain compatibility shims and also other "features" and conveniences.

It's these other "features" added by AppCompat that are effectively crippling the performance of EditText. If you create your own custom View that inherits from EditText instead of AppCompatEditText, you'll notice a huge improvement in performance.

You may want to look at the source code of AppCompatEditText and pick-and-choose any compatibility additions that you do want to migrate into your custom View, but it's very likely you won't need all of them.


btw, the apps you mention (such as Turbo Editor) have fast performance because they're using a much older version of AppCompat that doesn't have as many new "features" as the most recent version.

Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47
0

You could try to implement a custom view which is a RecyclerView. Each line is a new single EditText. I don't know how well the performance is. But you could give it a try.

Another tip is don't wrap the EditText inside a RelativeLayout. Use LinearLayout instead. A fixed width on the EditText will give also a performance boost. It prevents re-calculation and re-drawing of layout.

beeb
  • 1,615
  • 1
  • 12
  • 24