日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
AndroidUI控件組合應(yīng)用之一:建立數(shù)據(jù)模型

Android在UI部分為應(yīng)用程序開發(fā)人員提供了極大的便利和靈活性,在此就不一一列舉了,本文擬通過一個小例子窺見一斑。

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),肥鄉(xiāng)企業(yè)網(wǎng)站建設(shè),肥鄉(xiāng)品牌網(wǎng)站建設(shè),網(wǎng)站定制,肥鄉(xiāng)網(wǎng)站建設(shè)報(bào)價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,肥鄉(xiāng)網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

很多用過新浪微博手機(jī)客戶端Android版本的童鞋想必都對其主界面的效果印象深刻,見下左圖:

從圖中可以看到,主體的列表框是個很復(fù)雜的部分,既要能顯示頭像、微博內(nèi)容,又要能在微博內(nèi)容中顯示表情、圖片、@某人、URL,這些元素混雜在一起,對于某些平臺的UI開發(fā)來講,簡直太難了。但在Android上來開發(fā),確實(shí)很容易實(shí)現(xiàn),右圖就是本程序的運(yùn)行結(jié)果,重點(diǎn)展現(xiàn)了列表框部分的仿照。當(dāng)然,所用的圖片都是來自于新浪的了。

下面,我們就一起來看一下這個效果的代碼實(shí)現(xiàn)。

首先,需要定義數(shù)據(jù)模型,主要的數(shù)據(jù)抽象是Site、Blog、User,分別代表網(wǎng)站、博文、用戶,數(shù)據(jù)模型如下圖所示:

具體成員的含義就不解釋了。如果你沒用過新浪微博,建議去用一下,或者可以參考http://open.weibo.com/中的開發(fā)文檔。

這幾個類的代碼如下:

 
 
 
 
  1. view plaincopy to clipboardprint?  
  2. package com.wenbin.test.site;    
  3.     
  4. public class User{    
  5.     private String profileImageUrl="http://tp3.sinaimg.cn/1500460450/50/1289923764/0";    
  6.     private String screenName="測試";    
  7.     private boolean verified=false;    
  8.     
  9.     public User(){    
  10.             
  11.     }    
  12.     
  13.     public String getProfileImageUrl(){    
  14.         return profileImageUrl;    
  15.     }    
  16.     
  17.     public String getScreenName(){    
  18.         return screenName;    
  19.     }    
  20.     
  21.     public void setProfileImageUrl(String profileImageUrl) {    
  22.         this.profileImageUrl = profileImageUrl;    
  23.     }    
  24.     
  25.     public void setScreenName(String screenName) {    
  26.         this.screenName = screenName;    
  27.     }    
  28.     
  29.     public void setVerified(boolean verified) {    
  30.         this.verified = verified;    
  31.     }    
  32.     
  33.     public boolean isVerified(){    
  34.         return verified;    
  35.     }    
  36. }   

 

 
 
 
 
  1. view plaincopy to clipboardprint?  
  2. package com.wenbin.test.site;    
  3.     
  4. import java.util.Date;    
  5.     
  6. public class Blog implements Comparable{    
  7.     
  8.     private Date createAt=new Date(System.currentTimeMillis());    
  9.     private Blog retweetedBlog;    
  10.     private String text="就算把我打的遍體鱗傷也見不得會[淚]?http://blog.csdn.net/caowenbin @移動云_曹文斌 。";    
  11.     private String smallPic="";    
  12.     private String source="IE9";    
  13.     private User user;    
  14.     private Site site;    
  15.     
  16.     public Blog(){    
  17.     
  18.     }    
  19.         
  20.     public Blog(Site site){    
  21.         this.site=site;    
  22.     }    
  23.     
  24.     public boolean isHaveRetweetedBlog(){    
  25.         return retweetedBlog!=null;    
  26.     }    
  27.         
  28.     public Blog getRetweetedBlog(){    
  29.         return retweetedBlog;    
  30.     }    
  31.     
  32.     
  33.     public String getText(){    
  34.         return text;    
  35.     }    
  36.     
  37.     public User getUser(){    
  38.         return user;    
  39.     }    
  40.         
  41.     public String getSmallPic(){    
  42.         return smallPic;    
  43.     }    
  44.     
  45.     public void setRetweetedBlog(Blog retweetedBlog) {    
  46.         this.retweetedBlog = retweetedBlog;    
  47.     }    
  48.     
  49.     public void setText(String text) {    
  50.         this.text = text;    
  51.     }    
  52.         
  53.     public String getInReplyUserScreenName(){    
  54.         if (retweetedBlog!=null && retweetedBlog.getUser()!=null)    
  55.             return retweetedBlog.getUser().getScreenName();    
  56.         else    
  57.             return "";          
  58.     }    
  59.         
  60.     public String getInReplyBlogText(){    
  61.         if (retweetedBlog!=null)    
  62.             return retweetedBlog.getText();    
  63.         else    
  64.             return "";      
  65.     }    
  66.         
  67.     public void setPic(String smallPic){    
  68.         this.smallPic=smallPic;    
  69.     }    
  70.     
  71.     public void setUser(User user) {    
  72.         this.user = user;    
  73.     }    
  74.     
  75.     public int compareTo(Blog another) {    
  76.         int ret=0;    
  77.     
  78.         if (this.createAt.before(another.createAt)){    
  79.             ret=-1;    
  80.         }    
  81.         else if (this.createAt.after(another.createAt)){    
  82.             ret=1;    
  83.         }    
  84.         else{    
  85.             ret=0;      
  86.         }    
  87.     
  88.         return ret;    
  89.     }    
  90.     
  91.     public void setSource(String source) {    
  92.         this.source = source;    
  93.     }    
  94.     
  95.     public String getSource() {    
  96.         return source;    
  97.     }    
  98.     
  99.     public void setSite(Site site) {    
  100.         this.site = site;    
  101.     }    
  102.     
  103.     public Site getSite() {    
  104.         return site;    
  105.     }    
  106.     
  107. }   

 

 
 
 
 
  1. view plaincopy to clipboardprint?  
  2. package com.wenbin.test.site;    
  3.     
  4. import java.util.HashMap;    
  5. import java.util.Iterator;    
  6. import java.util.Map;    
  7. import java.util.Set;    
  8. import java.util.TreeSet;    
  9.     
  10.     
  11. public abstract class Site{    
  12.     
  13.     protected Set blogs=new TreeSet();    
  14.     protected String name;    
  15.     protected Map faceMap=new HashMap();    
  16.     
  17.     public Site() {    
  18.         onConstruct();    
  19.     }    
  20.     
  21.     protected abstract void onConstruct();    
  22.         
  23.     public Map getFaceMap() {    
  24.         return faceMap;    
  25.     }    
  26.         
  27.     public Set getBlogs(){    
  28.         return blogs;    
  29.     }    
  30.         
  31.     public long getBlogsCount(){    
  32.         return blogs.size();    
  33.     }    
  34.         
  35.     public void addBlog(Blog blog){    
  36.         blogs.add(blog);    
  37.     }    
  38.         
  39.     public void removeBlog(Blog blog){    
  40.         blogs.remove(blog);    
  41.     }    
  42.         
  43.     public Iterator getBlogsIterator(){    
  44.         return blogs.iterator();    
  45.     }    
  46.         
  47.     public void clearBlogs(){    
  48.         blogs.clear();    
  49.     }    
  50.     
  51.     public String getName(){    
  52.         return name;    
  53.     }    
  54. }   

 

 
 
 
 
  1. view plaincopy to clipboardprint?  
  2. package com.wenbin.test.site;    
  3.     
  4. public class SinaSite extends Site {    
  5.     
  6.     protected void onConstruct(){    
  7.         name="新浪微博";    
  8.         initFaceMap();    
  9.     }    
  10.     
  11.     private void initFaceMap(){    
  12.         faceMap.put("[呵呵]", "hehe");    
  13.         faceMap.put("[嘻嘻]", "xixi");    
  14.         faceMap.put("[哈哈]", "haha");    
  15.         faceMap.put("[愛你]", "aini");    
  16.         faceMap.put("[暈]", "yun");    
  17.         faceMap.put("[淚]", "lei");    
  18.     }    
  19. }   

 

先熟悉一下這些代碼,下次就利用這些數(shù)據(jù)來制作基本的列表框。


文章標(biāo)題:AndroidUI控件組合應(yīng)用之一:建立數(shù)據(jù)模型
分享鏈接:http://www.5511xx.com/article/cdsdhjc.html