A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

定义了一个NewsBean对于app的每个ListView的Item,Constaint是个接口,存放了一些常量,还有就是一些辅助类。

NewsItem.java

[java] view plaincopy
package com.zhy.bean;  
  
public class NewsItem  
{  
    private int id;  
  
    /**
     * 标题
     */  
    private String title;  
    /**
     * 链接
     */  
    private String link;  
    /**
     * 发布日期
     */  
    private String date;  
    /**
     * 图片的链接
     */  
    private String imgLink;  
    /**
     * 内容
     */  
    private String content;  
  
    /**
     * 类型   
     *  
     */  
    private int newsType;  
  
    public int getNewsType()  
    {  
        return newsType;  
    }  
  
    public void setNewsType(int newsType)  
    {  
        this.newsType = newsType;  
    }  
  
    public String getTitle()  
    {  
        return title;  
    }  
  
    public void setTitle(String title)  
    {  
        this.title = title;  
    }  
  
    public String getLink()  
    {  
        return link;  
    }  
  
    public void setLink(String link)  
    {  
        this.link = link;  
    }  
  
    public int getId()  
    {  
        return id;  
    }  
  
    public void setId(int id)  
    {  
        this.id = id;  
    }  
  
    public String getDate()  
    {  
        return date;  
    }  
  
    public void setDate(String date)  
    {  
        this.date = date;  
    }  
  
    public String getImgLink()  
    {  
        return imgLink;  
    }  
  
    public void setImgLink(String imgLink)  
    {  
        this.imgLink = imgLink;  
    }  
  
    public String getContent()  
    {  
        return content;  
    }  
  
    public void setContent(String content)  
    {  
        this.content = content;  
    }  
  
    @Override  
    public String toString()  
    {  
        return "NewsItem [id=" + id + ", title=" + title + ", link=" + link + ", date=" + date + ", imgLink=" + imgLink  
                + ", content=" + content + ", newsType=" + newsType + "]";  
    }  
  
}  

CommonException.java
[java] view plaincopy
package com.zhy.bean;  
  
public class CommonException extends Exception  
{  
  
    public CommonException()  
    {  
        super();  
        // TODO Auto-generated constructor stub  
    }  
  
    public CommonException(String message, Throwable cause)  
    {  
        super(message, cause);  
        // TODO Auto-generated constructor stub  
    }  
  
    public CommonException(String message)  
    {  
        super(message);  
        // TODO Auto-generated constructor stub  
    }  
  
    public CommonException(Throwable cause)  
    {  
        super(cause);  
        // TODO Auto-generated constructor stub  
    }  
      
}  

Constaint.java
[java] view plaincopy
package com.zhy.csdn;  
  
public interface Constaint  
{  
    public static final int NEWS_TYPE_YEJIE = 1;  
    public static final int NEWS_TYPE_YIDONG = 2;  
    public static final int NEWS_TYPE_YANFA = 3;  
    public static final int NEWS_TYPE_CHENGXUYUAN = 4;  
    public static final int NEWS_TYPE_YUNJISUAN = 5;   
      
  
}  
DataUtil.java
[java] view plaincopy
package com.zhy.csdn;  
  
import java.io.InputStream;  
import java.net.HttpURLConnection;  
import java.net.URL;  
  
import com.zhy.bean.CommonException;  
  
public class DataUtil  
{  
  
    /**
     * 返回该链接地址的html数据
     *  
     * @param urlStr
     * @return
     * @throws CommonException
     */  
    public static String doGet(String urlStr) throws CommonException  
    {  
        StringBuffer sb = new StringBuffer();  
        try  
        {  
            URL url = new URL(urlStr);  
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
            conn.setRequestMethod("GET");  
            conn.setConnectTimeout(5000);  
            conn.setDoInput(true);  
            conn.setDoOutput(true);  
  
            if (conn.getResponseCode() == 200)  
            {  
                InputStream is = conn.getInputStream();  
                int len = 0;  
                byte[] buf = new byte[1024];  
  
                while ((len = is.read(buf)) != -1)  
                {  
                    sb.append(new String(buf, 0, len, "UTF-8"));  
                }  
  
                is.close();  
            } else  
            {  
                throw new CommonException("访问网络失败!");  
            }  
  
        } catch (Exception e)  
        {  
            throw new CommonException("访问网络失败!");  
        }  
        return sb.toString();  
    }  
}  

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马