user3268403
user3268403

Reputation: 213

Android: Why does EditText make scrolling slow?

I created a scrollable custom ViewGroup which has several >200 EditTexts in it (not all of them are shown at the same time - I am using a recycler). The problem I am having is that the scrolling is very slow.

Interestingly, I don't have the problem if I do one of the following
1) disable the editText [editText.setEnabled(false)]

or

2) If I change the view from EditText to TextView

Any ideas on what the issue could be?

Upvotes: 2

Views: 1721

Answers (2)

Stephan Branczyk
Stephan Branczyk

Reputation: 9385

EditText is huge. Take a look especially at all those methods it inherits.

Why don't you try using just one EditText with 199 custom TextViews or a large grid of rectangles drawn within a Canvas? You could always customize your TextViews (or your drawn grid of rectangles) to make them look like edit boxes, but only use one EditText for the cell that has the focus itself.

That's even how Excel works for some of the functionality it has. It can edit a cell directly (yes), but it also has a static cell on the upper left of the Excel spreadsheet to show you the content of a formula (that may already be rendered as a view within the focused cell itself). You could do something similar yourself. You could extend an EditText to do all the hard stuff, like auto-complete, etc, but you could just draw the text inside the rectangle that has focus (or insert it inside the particular TextView that has focus).

Take a look at this example: https://github.com/dennis-sheil/android-spreadsheet

He seems to be using mostly TextViews (although TextViews are heavy too, I'm starting to think that the Canvas may be better for something like this, and that everything could be simulated with the drawing method, by everything I mean the blinking cursor, the highlighting of the cell, the character by character typing, etc). With the Canvas at least, you can easily tell it what part needs to be drawn, and what part is off the screen and doesn't need to be drawn, so you're less likely to get into memory problems.

Upvotes: 4

Piotr Ślesarew
Piotr Ślesarew

Reputation: 2836

It can be issue with focusing the EditText during the scroll or you create too much objects and it is slow. Use ListView with EditText. Recycle views using viewHolder pattern. It will be smooth but I'm not sure if it is what you are looking for.

Upvotes: 1

Related Questions