williamyyu/SimpleRatingBar

Can't inflate view in not UI thread

Alexinzaz opened this issue · 2 comments

If I want inflate view with SimpoleRatingBar in not UI thread I cath exeption:

android.view.InflateException: Binary XML file line #0: Error inflating class com.willy.ratingbar.ScaleRatingBar
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

`Thread {
val page = LayoutInflater.from(activity).inflate(view_pager_department_item, null)

}`

Hello @Alexinzaz ,
because the library needs to control the view's animation, the ScaleRatingBar needs a UI handler to process it.

so maybe you can not inflate view in not UI thread, or if you know any solution, please let me know.
Thanks for your help!

The view can post a runnable directly,not need new a Handler.
like this:
postDelayed(runnable,ANIMATION_DELAY);

after use "post" method,you can get handler object by method getHandler(),if you want to remove some runnable.