14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: Intents, Broadcast Receivers, Adapters, and the Internet<br />

152<br />

int end = magnitudeString.length()-1;<br />

double magnitude;<br />

magnitude = Double.parseDouble(magnitudeString.substring(0,<br />

end));<br />

details = details.split(“,”)[1].trim();<br />

Quake quake = new Quake(qdate, details, l,<br />

magnitude, linkString);<br />

// Process a newly found earthquake<br />

addNewQuake(quake);<br />

}<br />

}<br />

}<br />

} catch (MalformedURLException e) {<br />

e.printStackTrace();<br />

} catch (IOException e) {<br />

e.printStackTrace();<br />

} catch (ParserConfigurationException e) {<br />

e.printStackTrace();<br />

} catch (SAXException e) {<br />

e.printStackTrace();<br />

}<br />

finally {<br />

}<br />

}<br />

private void addNewQuake(Quake _quake) {<br />

// TODO: Add the earthquakes to the array list.<br />

}<br />

7. Update the addNewQuake method so that it takes each newly processed quake and adds it to the<br />

Earthquake ArrayList. It should also notify the Array Adapter that the underlying data have<br />

changed.<br />

private void addNewQuake(Quake _quake) {<br />

// Add the new quake to our list of earthquakes.<br />

earthquakes.add(_quake);<br />

}<br />

// Notify the array adapter of a change.<br />

aa.notifyDataSetChanged();<br />

8. Modify your onCreate method to call refreshEarthquakes on start-up.<br />

@Override<br />

public void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setContentView(R.layout.main);<br />

earthquakeListView =

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!