偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Android UI控件組合應(yīng)用之一:建立數(shù)據(jù)模型

移動開發(fā) Android
本文通過Android版本的新浪微博手機(jī)客戶端為例,介紹了Android代碼如何實現(xiàn)微博主體列表框,你能從中了解到Android在UI部分為應(yīng)用程序開發(fā)人員提供了極大的便利和靈活性。

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

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

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

下面,我們就一起來看一下這個效果的代碼實現(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<Blog>{    
  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<Blog> blogs=new TreeSet<Blog>();    
  14.     protected String name;    
  15.     protected Map<String,String> faceMap=new HashMap<String,String>();    
  16.     
  17.     public Site() {    
  18.         onConstruct();    
  19.     }    
  20.     
  21.     protected abstract void onConstruct();    
  22.         
  23.     public Map<String, String> getFaceMap() {    
  24.         return faceMap;    
  25.     }    
  26.         
  27.     public Set<Blog> 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<Blog> 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ù)來制作基本的列表框。

【編輯推薦】

  1. 詳解Android首選項框架ListPreference
  2. 谷歌最新平板系統(tǒng)Android 3.1細(xì)節(jié)詳解
  3. 深入淺出 詳解Android Surface系統(tǒng)
  4. 在Windows系統(tǒng)上安裝與使用Android NDK r5
  5. Android開發(fā):自定義GridView/ListView數(shù)據(jù)源
責(zé)任編輯:佚名 來源: CSDN博客
相關(guān)推薦

2011-06-01 14:20:37

Android

2021-02-28 22:20:25

2011-02-28 13:19:50

SQL Server SQL死鎖

2010-05-26 14:37:56

Cassandra數(shù)據(jù)

2009-09-18 14:07:51

LINQ to SQL

2012-03-05 10:54:03

NoSQL

2021-01-27 05:34:33

Python對象模型

2021-01-15 13:18:39

數(shù)據(jù)模型領(lǐng)域模型代碼

2011-08-10 15:36:26

iPhone靜態(tài)庫控件

2011-04-11 15:53:40

C++

2017-06-27 10:08:29

數(shù)據(jù)倉庫模型

2016-11-02 12:32:47

數(shù)據(jù)分析大數(shù)據(jù)模型

2010-08-11 09:29:25

FlexJava數(shù)據(jù)模型

2013-12-02 13:59:22

jQueryUI

2017-01-18 08:41:22

大數(shù)據(jù)畫像建設(shè)

2022-04-01 16:04:33

Harmonytabs容器鴻蒙

2021-07-14 10:09:05

架構(gòu)模型數(shù)據(jù)

2017-02-13 17:17:48

Android標(biāo)題欄控件

2022-12-09 09:39:01

數(shù)據(jù)治理

2022-08-15 14:49:12

物聯(lián)網(wǎng)數(shù)據(jù)模型存儲
點贊
收藏

51CTO技術(shù)棧公眾號