0

I am trying to batch-add several thousand spans to a SpannableStringBuilder in an EditText (obtained via getText()).

This is slower than I would like. Profiling has shown that the vast majority of the time is being spent in DynamicLayout.reflow. Is there a way to block the layout reflow until I am done adding spans?

hs1
  • 51
  • 1
  • 4

1 Answers1

0

To batch text reflow / layout changes use AppCompatMultiAutoCompleteTextView as your base class and surround the code you wish to batch with beginBatchEdit() and endBatchEdit()

i.e.


public class MyEditText extends AppCompatMultiAutoCompleteTextView {

    private void batchUpdateSpans() {
        try {
            beginBatchEdit();
            updateSpans();
        } finally {
            endBatchEdit();
        } 
    }

}

AppCompatMultiAutoCompleteTextView uses SpannableBuilder, a subclass of SpannableStringBuilder with batching support.

hs1
  • 51
  • 1
  • 4