title: Android ListView reload data
body: <p>Is it possible to reload a ListView once the data is downloaded? Basically I'm updating an app for 4.1 but my ListView downloads and parses an XML file, I know that I have to run this now in a background thread but when I open the activity via a tab the screen is blank. I am not sure how to get this to work or what part of the code I need to use in the background thread, can someone please help. Thank you.</p>
  
  <pre><code>    public class ThirdActivity extends ListActivity {
  
      // All static variables
      static final String URL = "http://selectukradio.com/SelectUKSchedule.xml";     //  http://api.androidhive.info/pizza/?format=xml  http://selectukradio.com/SelectUKSchedule.xml
      // XML node keys
      static final String KEY_ITEM = "day"; // parent node   item
      static final String KEY_ID = "link";     //  id
      static final String KEY_NAME = "dj";     // name
      static final String KEY_COST = "time";    // cost
      static final String KEY_DESC = "tempDay";    // description
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_3);
  
  
                      try{
                      ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
                      XMLParser parser = new XMLParser();
                      String xml = parser.getXmlFromUrl(URL); // getting XML
                      Document doc = parser.getDomElement(xml); // getting DOM element
  
  
                      NodeList nl = doc.getElementsByTagName(KEY_ITEM);
                      // looping through all item nodes &lt;item&gt;
                      for (int i = 0; i &lt; nl.getLength(); i++) {
                          // creating new HashMap
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                          Element e = (Element) nl.item(i);
                          // adding each child node to HashMap key =&gt; value
                          map.put(KEY_ID, parser.getValue(e, KEY_ID));
                          map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
                          map.put(KEY_COST, parser.getValue(e, KEY_COST));    // "Rs. " +
                          map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
  
                          // adding HashList to ArrayList
                          menuItems.add(map);
                      }
  
                      // Adding menuItems to ListView
                      ListAdapter adapter = new SimpleAdapter(ThirdActivity.this, menuItems,
                              R.layout.list_item,
                              new String[] { KEY_NAME, KEY_COST,KEY_DESC,KEY_ID }, new int[] {
                                      R.id.name, R.id.cost, R.id.day, R.id.link });
  
  
  
                      setListAdapter(adapter);
  
                      // selecting single ListView item
                      ListView lv = getListView();
  
                      lv.setOnItemClickListener(new OnItemClickListener() {
  
                          @Override
                          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
                              // getting values from selected ListItem
                              String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                              String cost = ((TextView) view.findViewById(R.id.cost)).getText().toString();
                              String link = ((TextView) view.findViewById(R.id.link)).getText().toString();
  
  
  
                              // Starting new intent
                              Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                              in.putExtra(KEY_NAME, name);
                              in.putExtra(KEY_COST, cost);
                              in.putExtra(KEY_ID, link);
                              startActivity(in);
  
                          }
                      });
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
  
      }   
  
  
  
  
      @Override public boolean onKeyDown(int keyCode, KeyEvent event) {  
  
  
          if (keyCode == KeyEvent.KEYCODE_BACK) {             
              Intent intent = new Intent();
              intent.setAction(Intent.ACTION_MAIN);
              intent.addCategory(Intent.CATEGORY_HOME);
              startActivity(intent);
              }     
  
          return super.onKeyDown(keyCode, event); 
          }
  }
  </code></pre>