Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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

Hello,

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

Code:
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!
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);
	    earthquakes.add(_quake);
addQuakeToArray also calls earthquakes.add(), doesn't it therefore get added twice?
Code:
	    addQuakeToArray(_quake);
	  }
	}

  /** 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.
	    earthquakes.add(_quake);

	    // Notify the array adapter of a change.
	    aa.notifyDataSetChanged();
	  }
	}
Thanks
Ian





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





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