起動すると、このエラーが発生します android.view.ViewRootImpl$CalledFromWrongThreadException: ビュー階層を作成した元のスレッドのみがそのビューにアクセスできます。
class FirstFragment : Fragment(){
private val TAG: String = "Information from app"
lateinit var response:Response<Reqres>
private lateinit var post :Reqres
public lateinit var listus :List<databases>
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
Log.i(TAG, "Info about onCreateView1")
val view = inflater.inflate(R.layout.fragment_first, container, false)
val recycle= view.findViewById<RecyclerView>(R.id.recyclerview)
recycle.layoutManager = LinearLayoutManager(activity)
GlobalScope.launch(Dispatchers.IO) {
response = App.getApi().getData().execute()
post=response.body()
listus = post.data
recycle.adapter = Recycleadapter(listus)
}
return view
}