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

成都創(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)價(jià),網(wǎng)絡(luò)營(yíng)銷(xiāo),網(wǎng)絡(luò)優(yōu)化,肥鄉(xiāng)網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專(zhuān)業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶(hù)成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
很多用過(guò)新浪微博手機(jī)客戶(hù)端Android版本的童鞋想必都對(duì)其主界面的效果印象深刻,見(jiàn)下左圖:
從圖中可以看到,主體的列表框是個(gè)很復(fù)雜的部分,既要能顯示頭像、微博內(nèi)容,又要能在微博內(nèi)容中顯示表情、圖片、@某人、URL,這些元素混雜在一起,對(duì)于某些平臺(tái)的UI開(kāi)發(fā)來(lái)講,簡(jiǎn)直太難了。但在Android上來(lái)開(kāi)發(fā),確實(shí)很容易實(shí)現(xiàn),右圖就是本程序的運(yùn)行結(jié)果,重點(diǎn)展現(xiàn)了列表框部分的仿照。當(dāng)然,所用的圖片都是來(lái)自于新浪的了。
下面,我們就一起來(lái)看一下這個(gè)效果的代碼實(shí)現(xiàn)。
首先,需要定義數(shù)據(jù)模型,主要的數(shù)據(jù)抽象是Site、Blog、User,分別代表網(wǎng)站、博文、用戶(hù),數(shù)據(jù)模型如下圖所示:
具體成員的含義就不解釋了。如果你沒(méi)用過(guò)新浪微博,建議去用一下,或者可以參考http://open.weibo.com/中的開(kāi)發(fā)文檔。
這幾個(gè)類(lèi)的代碼如下:
- view plaincopy to clipboardprint?
- package com.wenbin.test.site;
- public class User{
- private String profileImageUrl="http://tp3.sinaimg.cn/1500460450/50/1289923764/0";
- private String screenName="測(cè)試";
- private boolean verified=false;
- public User(){
- }
- public String getProfileImageUrl(){
- return profileImageUrl;
- }
- public String getScreenName(){
- return screenName;
- }
- public void setProfileImageUrl(String profileImageUrl) {
- this.profileImageUrl = profileImageUrl;
- }
- public void setScreenName(String screenName) {
- this.screenName = screenName;
- }
- public void setVerified(boolean verified) {
- this.verified = verified;
- }
- public boolean isVerified(){
- return verified;
- }
- }
- view plaincopy to clipboardprint?
- package com.wenbin.test.site;
- import java.util.Date;
- public class Blog implements Comparable
{ - private Date createAt=new Date(System.currentTimeMillis());
- private Blog retweetedBlog;
- private String text="就算把我打的遍體鱗傷也見(jiàn)不得會(huì)[淚]?http://blog.csdn.net/caowenbin @移動(dòng)云_曹文斌 。";
- private String smallPic="";
- private String source="IE9";
- private User user;
- private Site site;
- public Blog(){
- }
- public Blog(Site site){
- this.site=site;
- }
- public boolean isHaveRetweetedBlog(){
- return retweetedBlog!=null;
- }
- public Blog getRetweetedBlog(){
- return retweetedBlog;
- }
- public String getText(){
- return text;
- }
- public User getUser(){
- return user;
- }
- public String getSmallPic(){
- return smallPic;
- }
- public void setRetweetedBlog(Blog retweetedBlog) {
- this.retweetedBlog = retweetedBlog;
- }
- public void setText(String text) {
- this.text = text;
- }
- public String getInReplyUserScreenName(){
- if (retweetedBlog!=null && retweetedBlog.getUser()!=null)
- return retweetedBlog.getUser().getScreenName();
- else
- return "";
- }
- public String getInReplyBlogText(){
- if (retweetedBlog!=null)
- return retweetedBlog.getText();
- else
- return "";
- }
- public void setPic(String smallPic){
- this.smallPic=smallPic;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public int compareTo(Blog another) {
- int ret=0;
- if (this.createAt.before(another.createAt)){
- ret=-1;
- }
- else if (this.createAt.after(another.createAt)){
- ret=1;
- }
- else{
- ret=0;
- }
- return ret;
- }
- public void setSource(String source) {
- this.source = source;
- }
- public String getSource() {
- return source;
- }
- public void setSite(Site site) {
- this.site = site;
- }
- public Site getSite() {
- return site;
- }
- }
- view plaincopy to clipboardprint?
- package com.wenbin.test.site;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.TreeSet;
- public abstract class Site{
- protected Set
blogs=new TreeSet (); - protected String name;
- protected Map
faceMap=new HashMap (); - public Site() {
- onConstruct();
- }
- protected abstract void onConstruct();
- public Map
getFaceMap() { - return faceMap;
- }
- public Set
getBlogs(){ - return blogs;
- }
- public long getBlogsCount(){
- return blogs.size();
- }
- public void addBlog(Blog blog){
- blogs.add(blog);
- }
- public void removeBlog(Blog blog){
- blogs.remove(blog);
- }
- public Iterator
getBlogsIterator(){ - return blogs.iterator();
- }
- public void clearBlogs(){
- blogs.clear();
- }
- public String getName(){
- return name;
- }
- }
- view plaincopy to clipboardprint?
- package com.wenbin.test.site;
- public class SinaSite extends Site {
- protected void onConstruct(){
- name="新浪微博";
- initFaceMap();
- }
- private void initFaceMap(){
- faceMap.put("[呵呵]", "hehe");
- faceMap.put("[嘻嘻]", "xixi");
- faceMap.put("[哈哈]", "haha");
- faceMap.put("[愛(ài)你]", "aini");
- faceMap.put("[暈]", "yun");
- faceMap.put("[淚]", "lei");
- }
- }
先熟悉一下這些代碼,下次就利用這些數(shù)據(jù)來(lái)制作基本的列表框。
本文名稱(chēng):AndroidUI控件組合應(yīng)用之一:建立數(shù)據(jù)模型
文章位置:http://m.fisionsoft.com.cn/article/cdsdhjc.html


咨詢(xún)
建站咨詢(xún)
