开发者

Android Development: Using setText with SpannableString with Lots of Spans Slow, Workaround?

开发者 https://www.devze.com 2023-04-03 05:07 出处:网络
I\'ve made a little syntax highlighter for my app. It performs the regular expressions and applies the ForegroundColorSpans to a copy of the EditText\'s contect - all in a thread. Once all this is do

I've made a little syntax highlighter for my app.

It performs the regular expressions and applies the ForegroundColorSpans to a copy of the EditText's contect - all in a thread. Once all this is done, the setText() method gets called and replaces the EditText's context 开发者_开发知识库with the now-styled copy.

Problem is, the setText() method causes the UI to freeze. In a test I did with a 2,000 line file it took 30 seconds to apply the styled text!

Aside from recommending users that the syntax highlighting shouldn't be used with big files and automatically turning it off if they are opening a big file, what can I do to speed the syntax highlighting up? Apart from reducing and making the regular expressions more efficient.

Thanks, Alex.


Maybe you can use a WebView or alternatively try to develop some functionality so that only the text visible to the user is styled.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号