title: Calling runOnUiThread on database handler
body: <p>I built a function in database handler to grab data from sqlite + html page using jsoup.
  How can i set runOnUiThread to handle data of thread inside a database habdler function?
  or How can i attach returned data of thread to Activity from Database Handler file?</p>
  
  <p>files:</p>
  
  <p>-ListInvests.kt > to use DatabaseHandler function to attach data to ListAdapter</p>
  
  <p>-list_invests.xml > is the list items</p>
  
  <p>-startinvest_main.xml > is the view that will show list</p>
  
  <p>DatabaseHandler.kt  (code of thread only)</p>
  
  <pre><code>  Thread(Runnable {
                      var init_recent_price=StringBuilder()
                      try{
                          val doc = Jsoup.connect(url_link).get()
                          val table = doc.select("table")[0]
                          val tbody = table.select("tbody")
                          val rows = tbody.select("tr")
  
                          for (i in rows.indices) {
                              val row = rows[i]//
                              val cols = row.select("td")
                              //karat 21
                              if (i == 2 ) {
                                  karat_recent_price = cols[0].text()
  
                                  if(karat_recent_price.contains("إلى")){
                                      var splitter="إلى"
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
  
                                  }else {
                                      var splitter=" "
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
                                  }
                              }
  
                              //karat 18
                              if (i == 3 ) {
                                  karat_recent_price = cols[0].text()
                                  if(karat_recent_price.contains("إلى")){
                                      var splitter="إلى"
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
  
                                  }else {
                                      var splitter=" "
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
                                  }
                              }
  
                              //karat 24
                              if (i == 0 ) {
                                  karat_recent_price = cols[0].text()
  
                                  if(karat_recent_price.contains("إلى")){
                                      var splitter="إلى"
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
  
                                  }else {
                                      var splitter=" "
                                      val split_str=karat_recent_price.split(splitter)
                                      karat_recent_price=split_str[0]
                                      init_recent_price.append(karat_recent_price)  //show karat price text
                                  }
                              }
  
                              //inv_amount[index] , inv_enter_price[index] , karat_recent_price
                              var int_amount=amount
  
  
                              // new_amount=(int_amount * int_recent_price_string / int_enter_price).toString()
                              new_amount= karat_recent_price
                              catch_new_amount.append(new_amount)
  
  
                              if(new_amount &gt; int_amount){
                                  var inc=new_amount.toFloat() - int_amount.toFloat()
                                  var percent_inc=(inc/int_amount.toFloat())* 100
                                     percent=percent_inc.toString()
                                  init_percent_string=percent
                                  catch_percent.append(percent)
                              }else {
  
                                  var dec=int_amount.toFloat() - new_amount.toFloat()
                                  var percent_dec=(dec/int_amount.toFloat()) * 100
                                  percent=percent_dec.toString()
                                  init_percent_string=percent
                                  catch_percent.append(percent)
  
                              }
  
  
  
                          }//end for
  
                      }
                      catch(e: IOException){
                          e.printStackTrace()
                      }
  
                   //runOnUiThread  how to set it here?
  
                  }).start()
  </code></pre>