Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2010, 12:05 PM
Registered User
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chp Earthquakes


I'm enjoying the book, but I'm puzzled by a couple of the methods in the Earthquake class from Ch 6:

private void addNewQuake(Quake _quake) {
	  ContentResolver cr = getContentResolver();
	  // Construct a where clause to make sure we don’t already have this 
	  // earthquake in the provider.
	  String w = EarthquakeProvider.KEY_DATE + " = " + _quake.getDate().getTime();

	  // If the earthquake is new, insert it into the provider.
	  if (cr.query(EarthquakeProvider.CONTENT_URI, null, w, null, null).getCount() == 0){
I note that in the book, this is getCount>0, I'm glad to see it has been corrected in the downloaded code!
	    ContentValues values = new ContentValues();    

	    values.put(EarthquakeProvider.KEY_DATE, _quake.getDate().getTime());
	    values.put(EarthquakeProvider.KEY_DETAILS, _quake.getDetails());

	    double lat = _quake.getLocation().getLatitude();
	    double lng = _quake.getLocation().getLongitude();
	    values.put(EarthquakeProvider.KEY_LOCATION_LAT, lat);
	    values.put(EarthquakeProvider.KEY_LOCATION_LNG, lng);
	    values.put(EarthquakeProvider.KEY_LINK, _quake.getLink());
	    values.put(EarthquakeProvider.KEY_MAGNITUDE, _quake.getMagnitude());

	    cr.insert(EarthquakeProvider.CONTENT_URI, values);
addQuakeToArray also calls earthquakes.add(), doesn't it therefore get added twice?

  /** Add a new quake to the ArrayList */
	private void addQuakeToArray(Quake _quake) {
	  if (_quake.getMagnitude() > minimumMagnitude) {
	    // Add the new quake to our list of earthquakes.

	    // Notify the array adapter of a change.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this code work (chp.6)? wrockinator BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 3 December 3rd, 2008 03:16 AM
Chp.5 composite control properties studen77 BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 1 October 6th, 2006 03:35 PM
Chp 14 e-commerce JamesA BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 September 3rd, 2004 06:14 PM

All times are GMT -4. The time now is 08:26 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.