Environment: Android Studio 0.5.2, gradle 1.11, Kindle Fire
Time: 2014-3-24
Fixed location Information exception: http://blog.csdn.net/caroline_wendy/article/details/24465487
The earthquake project, mainly reads the Survey (subscription source) provided by the USGS (United States Geological feeds, the United States Bureau of Exploration) for displaying data;
Need to read the data on the Internet, format resolution (parse), the data type is atom type, similar to XML.
Subscription Source Address: Http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.atom
Format:
<feed xmlns= "Http://www.w3.org/2005/Atom" xmlns:georss= "Http://www.georss.org/georss" > <title>usgs Magnitude 2.5+ earthquakes, past day</title> <updated>2014-03-24T07:56:39Z</updated> <author > <name>u.s. Geological survey</name> <uri>http://earthquake.usgs.gov/</uri> </author > <id> http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.atom </id> <link rel= "se LF "href=" Http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.atom "/> <icon>http:// Earthquake.usgs.gov/favicon.ico</icon> <entry> <id>urn:earthquake-usgs-gov:ci:15479569</id > <title>m 2.9-9km W of Alberto Oviedo Mota, mexico</title> <UPDATED>2014-03-24T07:48:34.609Z&L t;/updated> <link rel= "Alternate type=" text/html "href=" http://earthquake.usgs.gov/earthquakes/eventpage/ ci15479569 "/> <summary type=" html > <! [cdata[;p class= "quicksummary" ><a href= "Http://earthquake.usgs.gov/earthquakes/eventpage/ci15479569#dyfi" Mmi-i "title=" Did you Feel It? Maximum reported intensity (0 reports) ">dyfi?" -<strong class= "Roman" >I</strong></a></p><dl><dt>Time</dt><dd> 2014-03-24 07:38:10 utc</dd><dd>2014-03-23 23:38:10-08:00 at epicenter</dd><dt>location< /dt><dd>32.222°n 115.274°w</dd><dt>depth</dt><dd>14.10 km (8.76 mi) </dd> </dl>]]> </summary> <georss:point>32.2215-115.274</georss:point> <georss:elev>- 14100</georss:elev> <category label= "age" term= "past Hour"/> <category label= "Magnitude" term= "Magnitu" De 2 "/> </entry> ... .....
Specific design of earthquake:
New project: Earthquake
1. New Quake (Quake.java) class, display seismic data.
Location: Java->package->quake
Package Mzx.spike.earthquake.app;
Import android.location.Location;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
public class Quake {private date date;
Private String details;
Private Location Location;
private double magnitude;
Private String link;
Public Date getDate () {return date;}
Public String Getdetails () {return details;}
Public Location getLocation () {return Location;}
Public double Getmagnitude () {return magnitude;}
Public String GetLink () {return link;}
Public Quake (Date _d, string _det, Location _loc, double _mag, string _link) {date = _d;
Details = _det;
location = _loc;
magnitude = _mag;
link = _link;
@Override public String toString () {SimpleDateFormat SDF = new SimpleDateFormat ("hh.mm");
String datestring = Sdf.format (date); Return DAtestring + ":" + magnitude + "" + details; }
}
Detailed
1. Types of display: date, dates; Details, detailed information, location; location, position; magnitude, magnitude; link, links;
2. Get () method, return information; constructor function, assigning initial value; ToString (), default output information;
2. Modify activity_main.xml and add fragment.
Location: Res->layout->activity_main.xml
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http:// Schemas.android.com/tools "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_ Horizontal_margin "
android:paddingtop=" @dimen/activity_vertical_margin "
android:paddingbottom=" @dimen Activity_vertical_margin "
tools:context=" mzx.spike.earthquake.app.MainActivity ">
<fragment Android:name= "Mzx.spike.earthquake.app.EarthquakeListFragment"
android:id= "@+id/earthquakelistfragment"
android:layout_width= "match_parent"
android:layout_height= "match_parent"
/>
</ Relativelayout>
Add fragment to specify the implementation (. java) file location.