Android “Only the original thread that created a view hierarchy can touch its views.”

后端 未结 28 3283
鱼传尺愫
鱼传尺愫 2020-11-21 04:44

I\'ve built a simple music player in Android. The view for each song contains a SeekBar, implemented like this:

public class Song extends Activity implement         


        
28条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 05:14

    In Kotlin simply put your code in runOnUiThread activity method

    runOnUiThread{
        // write your code here, for example
        val task = Runnable {
                Handler().postDelayed({
                    var smzHtcList = mDb?.smzHtcReferralDao()?.getAll()
                    tv_showSmzHtcList.text = smzHtcList.toString()
                }, 10)
    
            }
        mDbWorkerThread.postTask(task)
    }
    

提交回复
热议问题