title: How to update UI from background thread in a fragment
body: <p>I have an app that has a Fragment with a ListView. I ping IP addresses on the network and when I get a response I add the IP address to a list. Once I've finished pinging the IP addresses, I put this list of IP addresses that replied to my ping into a ListView.</p>
  
  <p>What I want to do is update this ListView as I'm pinging rather than doing after I've pinged all the IP addresses. To ping the IP addresses I'm using an AsyncTask which then calls a Runnable Thread. How do I tell the Fragment to update the UI from that Runnable class when I find an IP address?</p>
  
  <p>The rough layout of my classes is below.</p>
  
  <pre><code>public class FinderFragment extends ListFragment {
  
      private void CallFind(){
          new Find().execute();
      }
  
      private class Find extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected Void doInBackground(Void... voids) {
              SearchNetwork searchNetwork = new SearchNetwork(ipAddress);
              try {
                  searchNetwork.StartFind();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          protected void onPostExecute(Void aVoid) {
              super.onPostExecute(aVoid);
              UpdateDeviceList();
          }
      }
  }
  
  public class SearchNetwork {
  
      public void StartFind() throws InterruptedException {
          Thread t[] = new Thread[20];
          for(int i=0; i&lt;02; i++){
              t[i] = new Thread(new FindDevices(i*5));
              t[i].start();
          }
          for(Thread thread : t){
              thread.join();
          }
      }
  
      class FindDevices implements Runnable{
  
          @Override
          public void run() {
              //Ping the IP addresses here
              //I want to update UI from here
          }
      }
  </code></pre>