该App已经上传到百度应用市场:http://shouji.baidu.com/soft/item?docid=8928185&from=as&f=search_app_it%E8%B5%84%E8%AE%AF%40list_1_image%402%40header_all_input
有兴趣的可以下载看看。接下来我会公布源代码,不过该App并没有使用代码混淆,所以可以通过反编译清楚的看到源码。
首先是封装的对象:
public class NewsDto { private List<News>newses; private String nextPage; public List<News> getNewses(){ return newses; } public String getNextPage() { return nextPage; } public void setNextPage(String nextPage) { this.nextPage = nextPage; } public void setNewses(List<News> newses) { this.newses = newses; } }
public class News { /* 标题 */ private String title; /** * 摘要 */ private String sumary; /** * 内容 */ private String content; /** * 图片链接 */ private String imageLink; /** * 类型 */ private int type; /** * 上一篇 */ private String prevPassage; /** * 上一篇的url */ private String prevUrl; /** * 下一篇 */ private String nextPassage; /** * 下一篇的url */ private String nextUrl; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getSumary() { return sumary; } public void setSumary(String sumary) { this.sumary = sumary; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getImageLink() { return imageLink; } public void setImageLink(String imageLink) { this.imageLink = imageLink; } public int getType() { return type; } public void setType(int type) { this.type = type; } public String getPrevPassage() { return prevPassage; } public void setPrevPassage(String prevPassage) { this.prevPassage = prevPassage; } public String getNextPassage() { return nextPassage; } public void setNextPassage(String nextPassage) { this.nextPassage = nextPassage; } public String getPrevUrl() { return prevUrl; } public void setPrevUrl(String prevUrl) { this.prevUrl = prevUrl; } public String getNextUrl() { return nextUrl; } public void setNextUrl(String nextUrl) { this.nextUrl = nextUrl; } }
添加了一个新的业务方法,把html字符串转化为List对象:
一 :CSDN
public NewsDto getNews(String urlStr) throws CommonExecption { NewsDto newsDto = new NewsDto(); List<News> newses = new ArrayList<>(); String htmlStr = DataUtil.doGet(urlStr, "UTF-8"); Document doc = Jsoup.parse(htmlStr); // 获得文章中的第一个detail // System.out.println(htmlStr); Element detailEle = doc.select(".left .detail").get(0); // 标题 Element titleEle = detailEle.select("h1.title").get(0); News news = new News(); String title = titleEle.text(); title = AppUtil.encoding(title,"utf-8"); news.setTitle(title); news.setType(Constant.TITLE); newses.add(news); // 摘要 Element summaryEle = detailEle.select("div.summary").get(0); news = new News(); String summary = summaryEle.text(); summary = AppUtil.encoding(summary,"utf-8"); news.setSumary(summary); news.setType(Constant.SUMMARY); newses.add(news); // 内容 Element contentEle = detailEle.select("div.con.news_content").get(0); Elements childrenEle = contentEle.children(); for (Element child : childrenEle) { Elements imgEles = child.getElementsByTag("img"); // 图片 if (imgEles.size() > 0) { for (Element imgEle : imgEles) { if (imgEle.attr("src").equals("")) continue; news = new News(); String imgLink = imgEle.attr("src"); imgLink = AppUtil.encoding(imgLink,"utf-8"); news.setImageLink(imgLink); news.setType(Constant.IMG); newses.add(news); } } // 移除图片 imgEles.remove(); if (child.text().equals("")) continue; news = new News(); news.setType(Constant.CONTENT); try { if (child.children().size() == 1) { Element cc = child.child(0); if (cc.tagName().equals("b")) { news.setType(Constant.BOLD_TITLE); } } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } String content = child.outerHtml(); content = AppUtil.encoding(content,"utf-8"); news.setContent(content); newses.add(news); } newsDto.setNewses(newses); return newsDto; }
二 :51CTO:
/** * 开发技术 * * @param urlStr * @return * @throws CommonExecption */ public NewsDto getNewsDevelopment1(String urlStr) throws CommonExecption { int index = 0; NewsDto newsDto = new NewsDto(); List<News> newses = new ArrayList<News>(); String htmlStr = DataUtil.doGet(urlStr,"GB2312"); Document doc = Jsoup.parse(htmlStr); // ±êÌâ Element detailEle = doc.select(".showTitleBOx .showTitle").get(0); News news = new News(); news.setTitle(detailEle.text()); news.setType(Constant.TITLE); newses.add(news); Element contentEle2 = doc.select(".showContent").get(0); Elements childrenEle = contentEle2.children(); for (Element element : childrenEle) { if (element.getElementsByTag("h3").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h3").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("h1").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h1").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("h2").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h2").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("h4").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h4").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("img").size() != 0) { Elements imgEles = element.getElementsByTag("img"); // ͼƬ if (imgEles.size() > 0) { // System.out.println("img------>"+imgEles.attr("href")); for (Element imgEle : imgEles) { if (imgEle.attr("src").equals("")) continue; news = new News(); news.setImageLink(imgEle.attr("src")); news.setType(Constant.IMG); newses.add(news); } } imgEles.remove(); } if (element.getElementsByTag("a").size() != 0) { Elements imgEles = element.getElementsByTag("a"); // ͼƬ if (imgEles.size() > 0) { // System.out.println("img------>"+imgEles.attr("href")); for (Element imgEle : imgEles) { if (imgEle.attr("href").equals("")) continue; news = new News(); news.setImageLink(imgEle.attr("href")); news.setType(Constant.IMG); newses.add(news); } } imgEles.remove(); } if (element.text().equals("")) continue; /* if (element.getElementsByTag("span").size() != 0) { Elements contentEle3 = element.getElementsByTag("span"); news = new News(); String content = contentEle3.text(); byte[] bytes = { (byte) 0xC2, (byte) 0xA0 }; try { String UTFSpace = new String(bytes, "utf-8"); content = content.replace(UTFSpace, " "); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } */ if (element.getElementsByTag("p").size() != 0) { Elements contentEle3 = element.getElementsByTag("p"); news = new News(); String content = contentEle3.text(); content=AppUtil.encoding(content,"gb2312"); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("pre").size() != 0) { Elements contentEle4 = element.getElementsByTag("pre"); news = new News(); String content1 = contentEle4.text(); byte[] bytes1 = { (byte) 0xC2, (byte) 0xA0 }; try { String UTFSpace = new String(bytes1, "utf-8"); content1 = content1.replace(UTFSpace, " "); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } news.setContent(content1); news.setType(Constant.CONTENT); newses.add(news); } } // System.out.println("content------"+content4); String nextPageUri = "http://wuyvzhang.blog.51cto.com"; Element nextPage = doc.select(".prevNext").get(0); String uri = nextPage.getElementsByTag("a").attr("href"); newsDto.setNextPage(nextPageUri + uri); // ÄÚÈÝ newsDto.setNewses(newses); return newsDto; }
三 博客园:
public NewsDto getNewsDevelopment1(String urlStr, int cutrrent, int newType) throws CommonExecption { NewsDto newsDto = new NewsDto(); List<News> newses = new ArrayList<News>(); String htmlStr = BlogHouseDataUtil.doGet(urlStr, cutrrent, newType); Document doc = Jsoup.parse(htmlStr); // 标题 Element detailEle = doc.select(".post").get(0); String title = doc.getElementById("cb_post_title_url").text(); title=AppUtil.encoding(title,"utf-8"); News news = new News(); news.setTitle(title); news.setType(Constant.TITLE); newses.add(news); //Element contentEle2 = detailEle.select(".postBody").get(0); Element contentEle31 = detailEle.getElementById("cnblogs_post_body"); Elements childrenEle = contentEle31.children(); for (Element element : childrenEle) { if (element.getElementsByTag("h3").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h3").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("ul").size() != 0) { // Elements elements = element.getElementsByTag("ul"); // for (Element element1 : elements) { news = new News(); StringBuffer sb =new StringBuffer(); if (element.getElementsByTag("li").text() != null) { String content=element.getElementsByTag("li").text(); news.setContent(sb.append(content).append("\n").toString()); news.setType(Constant.CONTENT); newses.add(news); } else { news.setContent(element.getElementsByTag("a").text()); news.setType(Constant.CONTENT); newses.add(news); } // } } if (element.getElementsByTag("h1").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h1").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("h2").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h2").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("h4").size() != 0) { news = new News(); news.setContent(element.getElementsByTag("h4").text()); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementById("blogCustomTitleStyle") != null) { Element contentEle3 = element.getElementById("blogCustomTitleStyle"); news = new News(); String content = contentEle3.text(); content=AppUtil.encoding(content,"gb2312"); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } else if (element.getElementsByTag("p").size() != 0) { news = new News(); String content=element.getElementsByTag("p").text(); content=AppUtil.encoding(content,"gb2312"); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementById("blogCustomTitleIco") != null) { Element contentEle3 = element.getElementById("blogCustomTitleIco"); news = new News(); String content = contentEle3.text(); content=AppUtil.encoding(content,"gb2312"); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } if (element.getElementsByTag("img").size() != 0) { Elements imgEles = element.getElementsByTag("img"); // ͼƬ if (imgEles.size() > 0) { // System.out.println("img------>"+imgEles.attr("href")); for (Element imgEle : imgEles) { if (imgEle.attr("src").equals("")) continue; news = new News(); news.setImageLink(imgEle.attr("src")); news.setType(Constant.IMG); newses.add(news); } } imgEles.remove(); } if (element.getElementsByTag("a").size() != 0) { Elements imgEles = element.getElementsByTag("a"); // 图片 if (imgEles.size() > 0) { for (Element imgEle : imgEles) { if (imgEle.attr("href").equals("")) continue; news = new News(); String image = imgEle.attr("href"); if (image.endsWith(".jpg") || image.endsWith(".png") || image.endsWith(".gif")) { news.setImageLink(image); news.setType(Constant.IMG); newses.add(news); } } } imgEles.remove(); } if (element.text().equals("")) continue; /* if (element.getElementsByTag("span").size() != 0) { String content = element.getElementsByTag("p").text(); content=AppUtil.encoding(content,"gb2312"); news = new News(); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } */ if (element.getElementsByTag("pre").size() != 0) { Elements contentEle4 = element.getElementsByTag("pre"); news = new News(); String content = contentEle4.text(); content=AppUtil.encoding(content,"utf-8"); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } } Element element =doc.getElementById("post_next_prev"); String prevPageUrl=element.getElementsByTag("a").attr("href"); String prevTitle=element.getElementsByTag("a").text(); news =new News(); news.setPrevPassage(prevTitle); news.setPrevUrl(prevPageUrl); news.setType(Constant.PREV); newsDto.setNewses(newses); return newsDto; }
四 ITEYE
public NewsDto getNewsDevelopment1(String urlStr) throws CommonExecption { NewsDto newsDto = new NewsDto(); List<News> newses = new ArrayList<News>(); String htmlStr = ITeyeDataUtil.doGet(urlStr); // System.out.println("title------"+htmlStr); Document doc = Jsoup.parse(htmlStr); News news = null; if (doc.select(".title").size() > 0) { Element detailEle = doc.select(".title").get(0); String title = detailEle.getElementsByTag("a").get(0).text(); news = new News(); news.setTitle(title); news.setType(Constant.TITLE); newses.add(news); } if (doc.select(".title_block").size() > 0) { Element element = doc.select(".title_block").get(0); String title = element.getElementsByTag("a").get(1).text(); news = new News(); news.setTitle(title); news.setType(Constant.TITLE); newses.add(news); } if (doc.select(".blog_title").size() > 0) { Element element = doc.select(".blog_title").get(0); String title = element.getElementsByTag("a").get(0).text(); news = new News(); news.setContent(title); news.setType(Constant.CONTENT); newses.add(news); } if (doc.select(".blog_content").size() > 0) { Element element = doc.select(".blog_content").get(0); String content = element.text(); String[] content1 = content.split("。"); for (int i=0;i<content1.length;i++){ news=new News(); news.setType(Constant.CONTENT); news.setContent(content1[i]); newses.add(news); } } if (doc.getElementById("news_content") != null) { Element element = doc.getElementById("news_content"); String content1 = element.text(); String[] content2 = content1.split("。"); for (int i = 0; i < content2.length; i++) { news = new News(); news.setContent(content2[i] + "。"); news.setType(Constant.CONTENT); newses.add(news); } if (doc.getElementsByTag("li").size() < 0) { news = new News(); StringBuffer sb = new StringBuffer(); String content = sb.append(doc.getElementsByTag("li").text()).append("\n").toString(); news.setContent(content); news.setType(Constant.CONTENT); newses.add(news); } if (doc.getElementsByTag("img").size() > 0) { Elements imgEles = element.getElementsByTag("img"); if (imgEles.size() > 0) { for (Element imgEle : imgEles) { if (imgEle.attr("src").equals("")) continue; news = new News(); news.setImageLink(imgEle.attr("src")); news.setType(Constant.IMG); newses.add(news); } } imgEles.remove(); } } if (doc.getElementById("interview_main") != null) { Element element = doc.getElementById("interview_main"); if (doc.getElementById("interview_menu") != null) { Element element2 = doc.getElementById("interview_menu"); String content = element2.getElementsByTag("h4").text(); news = new News(); news.setType(Constant.CONTENT); news.setContent(content); newses.add(news); } if (element.getElementsByTag("li").size() > 0) { Elements elements = element.getElementsByTag("li"); for (Element element1 : elements) { news = new News(); news.setType(Constant.CONTENT); news.setContent(element1.getElementsByTag("li").text()); newses.add(news); } } if (element.getElementsByTag("h2") != null) { Elements element1=element.getElementsByTag("h2"); for (Element element2 :element1) news = new News(); news.setType(Constant.CONTENT); news.setContent(element1.text()); newses.add(news); } } if (doc.select(".news_content").size() > 0) { Elements contentEle31 = doc.select(".news_content"); for (Element element3 : contentEle31) { if (element3.getElementsByTag("div").size() != 0) { if (element3.getElementsByTag("img").size() != 0) { Elements imgEles = element3.getElementsByTag("img"); if (imgEles.size() > 0) { for (Element imgEle : imgEles) { if (imgEle.attr("src").equals("")) continue; news = new News(); news.setImageLink(imgEle.attr("src")); news.setType(Constant.IMG); newses.add(news); imgEles.remove(); } } } String content = element3.getElementsByTag("div").get(0).text(); byte[] bytes = {(byte) 0xC2, (byte) 0xA0}; try { String UTFSpace = new String(bytes, "utf-8"); content = content.replace(UTFSpace, " "); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String[] content2 = content.split("。"); for (int i = 0; i < content2.length; i++) { news = new News(); news.setContent(content2[i]); news.setType(Constant.CONTENT); newses.add(news); } } } } newsDto.setNewses(newses); return newsDto; }
上一教程已经完成了Xlist的显示,上拉与下拉,现在给它添加OnItemClickListener:
mXlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { NewsItem newsItem = mDatas.get(position-1); NewsItem nextItem=mDatas.get(position); Intent intent=null; if (newTypes_iteye==17){ intent = new Intent(getActivity(), SubjectsActivity.class); intent.putExtra("url", newsItem.getLink()); }else { intent = new Intent(getActivity(), NewsContentActivity.class); intent.putExtra("url", newsItem.getLink()); intent.putExtra("nextUrl", nextItem.getLink()); intent.putExtra("select", select); intent.putExtra("cuttenrPage", currentPage); } startActivity(intent); } });
到达显示内容的Activity页面:
public class NewsContentActivity extends BaseActivityImpl implements IXListViewLoadMore { private XListView listView; /** * 该页面的URL */ private String url; //下一篇文章的url private String nextUrl; //选的是哪个博客; private int select; //当前的是那一页 private int currentPage; private NewsItemBiz newsItemBiz; private NewItem51CTO newItem51CTO; private NewItemBlogHouse newItemBlogHouse; private NewItemITeye newItemITeye; private List<News> data; private ProgressBar progressBar; private NewsContentAdapter adapter; private ImageView nextPage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news_content); Bundle bundle = getIntent().getExtras(); url = bundle.getString("url"); nextUrl=bundle.getString("nextUrl"); select=bundle.getInt("select"); currentPage=bundle.getInt("currentPage"); initBiz(); adapter = new NewsContentAdapter(this,select); listView = (XListView) findViewById(R.id.id_listview); progressBar = (ProgressBar) findViewById(R.id.id_newsContentPro); nextPage=(ImageView)findViewById(R.id.next); nextPage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(NewsContentActivity.this,NewsContentActivity.class); intent.putExtra("url",nextUrl); startActivity(intent); } }); listView.setAdapter(adapter); listView.disablePullRefreash(); listView.setPullLoadEnable(this); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { News news = data.get(position - 1); switch (view.getId()) { case R.id.imageView: String imageLink = news.getImageLink(); Intent intent = new Intent(NewsContentActivity.this, ImageShowActivity.class); intent.putExtra("url", imageLink); startActivity(intent); break; case R.id.prev: Intent prevIntent=new Intent(NewsContentActivity.this,NewsContentActivity.class); prevIntent.putExtra("url",news.getPrevUrl()); startActivity(prevIntent); break; case R.id.next: Intent nextIntent=new Intent(NewsContentActivity.this,NewsContentActivity.class); nextIntent.putExtra("url",news.getNextUrl()); startActivity(nextIntent); break; } } }); new LoadDataTask().execute(); } /** * 初始化Biz */ public void initBiz(){ newsItemBiz = new NewsItemBiz(); newItem51CTO=new NewItem51CTO(); newItemBlogHouse=new NewItemBlogHouse(); newItemITeye=new NewItemITeye(); } @Override public void onLoadMore() { } class LoadDataTask extends AsyncTask<Void,Void,Void>{ @Override protected void onPreExecute() { progressBar.setVisibility(View.VISIBLE); } @Override protected Void doInBackground(Void... params) { try { switch (select){ case 1: data = newsItemBiz.getNews(url).getNewses(); break; case 2: data = newItem51CTO.getNewsDevelopment1(url).getNewses(); break; case 3: data = newItemBlogHouse.getNewsDevelopment1(url,currentPage,select).getNewses(); break; case 4: data = newItemITeye.getNewsDevelopment1(url).getNewses(); break; case 5: String html= ITeyeDataUtil.doGet(url); data = newItemITeye.getSubjectDTO(html).getNewses(); for (News news :data){ System.out.println("content------>"+news.getContent()); } break; } }catch (CommonExecption e){ Looper.prepare(); Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); Looper.loop(); } return null; } @Override protected void onPostExecute(Void aVoid) { if(data==null) return; adapter.addList(data); adapter.notifyDataSetChanged(); progressBar.setVisibility(View.GONE); } } /** * 点击返回按钮 * @param view */ public void back(View view){ finish(); } @Override protected void onResume() { super.onResume(); MobclickAgent.onResume(this); } @Override protected void onPause() { super.onPause(); MobclickAgent.onPause(this); } }
接下来看这个Activity中ListView的Adapter
public class NewsContentAdapter extends BaseAdapter { private LayoutInflater inflater; private List<News> data = new ArrayList<>(); private int select; //进入的是那个博客 private ImageLoader imageLoader = ImageLoader.getInstance(); private DisplayImageOptions options; public NewsContentAdapter(Context context,int select) { this.select=select; inflater = LayoutInflater.from(context); imageLoader.init(ImageLoaderConfiguration.createDefault(context)); selectPicture(select); } public void selectPicture(int select){ switch (select){ case 1: options = new DisplayImageOptions.Builder().showStubImage(R.drawable.images) .showImageForEmptyUri(R.drawable.images).showImageOnFail(R.drawable.images).cacheInMemory() .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565) .displayer(new FadeInBitmapDisplayer(300)).build(); break; case 2: options = new DisplayImageOptions.Builder().showStubImage(R.drawable.cto) .showImageForEmptyUri(R.drawable.cto).showImageOnFail(R.drawable.cto).cacheInMemory() .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565) .displayer(new FadeInBitmapDisplayer(300)).build(); break; case 3: options = new DisplayImageOptions.Builder().showStubImage(R.drawable.blog_house) .showImageForEmptyUri(R.drawable.blog_house).showImageOnFail(R.drawable.blog_house).cacheInMemory() .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565) .displayer(new FadeInBitmapDisplayer(300)).build(); break; case 4: options = new DisplayImageOptions.Builder().showStubImage(R.drawable.iteye) .showImageForEmptyUri(R.drawable.iteye).showImageOnFail(R.drawable.iteye).cacheInMemory() .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565) .displayer(new FadeInBitmapDisplayer(300)).build(); break; } } public void addList(List<News> datas) { data.addAll(datas); } @Override public int getCount() { return data == null ? 0 : data.size(); } @Override public Object getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return position; } @Override public int getItemViewType(int position) { switch (data.get(position).getType()) { case Constant.TITLE: return 0; case Constant.SUMMARY: return 1; case Constant.CONTENT: return 2; case Constant.IMG: return 3; case Constant.BOLD_TITLE: return 4; case Constant.PREV: return 5; case Constant.NEXT: return 6; } return -1; } @Override public int getViewTypeCount() { return 7; } @Override public boolean isEnabled(int position) { switch (data.get(position).getType()) { case Constant.IMG: return true; case Constant.PREV: return true; case Constant.NEXT: return true; default: return false; } } @Override public View getView(int position, View convertView, ViewGroup parent) { News news=data.get(position); //获取当前数据项 ViewHolder holder=null; if(convertView==null){ holder=new ViewHolder(); switch (news.getType()){ case Constant.TITLE: convertView=inflater.inflate(R.layout.news_content_title_item,null); holder.textView=(TextView)convertView.findViewById(R.id.text); break; case Constant.SUMMARY: convertView=inflater.inflate(R.layout.news_content_summary_item,null); holder.textView=(TextView)convertView.findViewById(R.id.text); break; case Constant.CONTENT: convertView=inflater.inflate(R.layout.news_content_item,null); holder.textView=(TextView)convertView.findViewById(R.id.text); break; case Constant.IMG: convertView=inflater.inflate(R.layout.news_content_img_item,null); holder.imageView=(ImageView)convertView.findViewById(R.id.imageView); break; case Constant.BOLD_TITLE: convertView=inflater.inflate(R.layout.news_content_bold_title_item,null); holder.textView=(TextView)convertView.findViewById(R.id.text); break; case Constant.PREV: convertView=inflater.inflate(R.layout.news_content_prev_item,null); holder.textView=(TextView)convertView.findViewById(R.id.prev); break; case Constant.NEXT: convertView=inflater.inflate(R.layout.news_content_next_item,null); holder.textView=(TextView)convertView.findViewById(R.id.next); break; } convertView.setTag(holder); }else { holder=(ViewHolder)convertView.getTag(); } if (null != news) { switch (news.getType()) { case Constant.IMG: imageLoader.displayImage(news.getImageLink(), holder.imageView, options); break; case Constant.TITLE: holder.textView.setText(news.getTitle()); break; case Constant.SUMMARY: holder.textView.setText(news.getSumary()); break; case Constant.CONTENT: if (select==1){ holder.textView.setText("\u3000\u3000"+ Html.fromHtml(news.getContent())); }else { holder.textView.setText("\u3000\u3000"+ news.getContent()); } break; case Constant.BOLD_TITLE: holder.textView.setText("\u3000\u3000"+Html.fromHtml(news.getContent())); case Constant.PREV: String prevTitle=news.getPrevPassage(); if(prevTitle==null) { holder.textView.setVisibility(View.GONE); }else { holder.textView.setText("上一篇"+prevTitle); } case Constant.NEXT: String nextTitle=news.getPrevPassage(); if(nextTitle==null) { holder.textView.setVisibility(View.GONE); }else { holder.textView.setText("上一篇"+nextTitle); } } } return convertView; } private final class ViewHolder{ TextView textView; ImageView imageView; } }