F
F
foonfyrick2020-08-17 12:02:01
Android
foonfyrick, 2020-08-17 12:02:01

Data is taken from the page in the Thread, how to wait for data to be received?

Thread(Runnable {
            document=Jsoup.connect("......").get()

            val elements:Elements=document.getElementsByClass("nbl-slimPosterBlock__title")
  
                elements.forEach {
                 arrayList1.add(DataCard(it.text()))
                }
// здесь  размер массива равен 144
        }).start()
//здесь размер массива равен 0

The list should be displayed on the screen after starting the application, but it does not display anything, because the data does not have time to turn out, as an array of 0 elements is already displayed. How to delay it until the data is received?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmtm, 2020-08-17
@foonfyrick

output array here: // here array size is 144
wrap output in runOnUiThread
read about LIveData and MVVM

S
szanislo, 2020-08-17
@szanislo

Use AsyncTask

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question