fun setRecentToTextView() {
executor.execute(Runnable {
var tmp = getRecentFromDB()
if(tmp.size <1){
frameLayout1.visibility = FrameLayout.VISIBLE
frameLayout2.visibility = FrameLayout.INVISIBLE
}
else {
frameLayout1.visibility = FrameLayout.INVISIBLE
frameLayout2.visibility = FrameLayout.VISIBLE
content_textView.setText(tmp[0].content)
currentRecentIndex = tmp[0].index
}
})
}
首先,getRecentFromDB()函数具有按房间库进行数据库访问的功能。因此,应该在不是main的线程中调用它。 其次,setRecentToTextView()函数用于更改每个frameLayout的可见性并设置片段的textview。 但这是由于执行者线程对视图的访问错误而导致的错误。
有什么方法可以避免此问题?