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