新聞中心
本篇內(nèi)容介紹了“Android XML提要怎么實(shí)現(xiàn)”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
成都創(chuàng)新互聯(lián)公司專注于贛縣企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,電子商務(wù)商城網(wǎng)站建設(shè)。贛縣網(wǎng)站建設(shè)公司,為贛縣等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
通過允許日期和鏈接作為簡單的對象被訪問,同時將它們表示為較強(qiáng)類型的對象(de >java.util.Datede > 和 de >java.net.URLde >),它隱藏了一些內(nèi)部狀態(tài)。它是一個典型的 Value Object,因此它基于其內(nèi)部狀態(tài)實(shí)現(xiàn)了 de >equals()de > 和 de >hashCode()de >。它還實(shí)現(xiàn)了 de >Comparablede > 接口,因此您可以使用它進(jìn)行排序(按日期)。在實(shí)踐中,提要中的數(shù)據(jù)始終是有序的,因?yàn)闆]有必要再進(jìn)行排序。
每個解析器實(shí)現(xiàn)都需要提供一個 URL 給 Androidster 提要,并使用它打開一個到 Androidster 站點(diǎn)的 HTTP 連接。這一常見行為自然是在 Java 代碼中建模,我們使用了一個抽象基類,所示。
基本提要解析器類
java代碼:
public abstract class BaseFeedParser implements FeedParser { // names of the XML tags static final String PUB_DATE = "pubDate"; static final String DESCRIPTION = "description"; static final String LINK = "link"; static final String TITLE = "title"; static final String ITEM = "item"; final URL feedUrl; protected BaseFeedParser(String feedUrl){ try { this.feedUrl = new URL(feedUrl); } catch (MalformedURLException e) { throw new RuntimeException(e); } } protected InputStream getInputStream() { try { return feedUrl.openConnection().getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } } }
基類存儲 de >feedUrlde > 并使用它打開了一個 de >java.io.InputStreamde >。如果出現(xiàn)任何差錯,它會拋出一個 de >RuntimeExceptionde >,造成應(yīng)用程序出現(xiàn)故障?;愡€為標(biāo)記的名稱定義了一些簡單的常量。顯示了提要中的一些示例內(nèi)容,以便于您理解這些標(biāo)記的重要性。
示例 XML 提要
java代碼:
< ?xml version="1.0" encoding="UTF-8"? >
< !-- generator="FeedCreator 1.7.2" -- >
< rss version="2.0" >
< channel >
< title >android_news< /title >
< description >android_news< /description >
< link >< /link >
< lastBuildDate >Sun, 19 Apr 2009 19:43:45 +0100< /lastBuildDate >
< generator >FeedCreator 1.7.2< /generator >
< item >
< title >Samsung S8000 to Run Android, Play DivX, Take Over the World< /title >
< link >< /link >
< description >More details have emerged on the first Samsung handset
to run Android. A yet-to-be announced phone called the S8000 is being
reported ...< /description >
< pubDate >Thu, 16 Apr 2009 07:18:51 +0100< /pubDate >
< /item >
< item >
< title >Android Cupcake Update on the Horizon< /title >
< link >< /link >
< description >After months of discovery and hearsay, the Android
build that we have all been waiting for is about to finally make it
out ...< /description >
< pubDate >Tue, 14 Apr 2009 04:13:21 +0100< /pubDate >
< /item >
< /channel >
< /rss >
“Android XML提要怎么實(shí)現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
當(dāng)前題目:AndroidXML提要怎么實(shí)現(xiàn)
鏈接分享:http://www.dlmjj.cn/article/ppsich.html