tailieunhanh - professional android application development phần 5

Context Menu được chọn trong vòng cuối. Một thực hiện bộ xương được hiển thị dưới đây:Bắt đầu bằng cách nhập khẩu các gói bạn cần phải hỗ trợ chức năng trình đơn vào các lớp học cuối khẩu nhập khẩu nhập khẩu | Chapter 5 Intents Broadcast Receivers Adapters and the Internet ArrayAdapter Quake aa ArrayList Quake earthquakes new ArrayList Quake Override public void onCreate Bundle icicle icicle setContentView earthquakeListView ListView int layoutID aa new ArrayAdapter Quake this layoutID earthquakes aa 4. Next you should start processing the earthquake feed. For this example the feed used is the 1-day USGS feed for earthquakes with a magnitude greater than . Add the location of your feed as an external string resource. This lets you potentially specify a different feed based on a user s location. xml version encoding utf-8 resources string name app_name Earthquake string string name quake_feed http eqcenter catalogs string resources 5. Before your application can access the Internet it needs to be granted permission for Internet access. Add the uses-permission to the manifest. uses-permission xmlns android http apk res android android name uses-permission 6. Returning to the Earthquake Activity create a new refreshEarthquakes method that connects to and parses the earthquake feed. Extract each earthquake and parse the details to obtain the date magnitude link and location. As you finish parsing each earthquake pass it in to a new addNewQuake method. The XML parsing is presented here without further comment. private void refreshEarthquakes Get the XML URL url try String quakeFeed getString url new URL quakeFeed URLConnection connection 150 Chapter 5 Intents Broadcast Receivers Adapters and the Internet connection HttpURLConnection httpConnection HttpURLConnection connection int responseCode if responseCode InputStream in .

TỪ KHÓA LIÊN QUAN