@Override protected Bitmap doInBackground(Void... arg0) { if (t_interaction_news.getPicture_path() != null && t_interaction_news.getPicture_path().length() > 0) { String imageuri = ""; imageuri += network_interface_paths.get_project_root; imageuri += t_interaction_news.getPicture_path(); System.out.println("imageurl-->" + imageuri); utils_picture_caches.getInstance().init(getActivity()); // 初始化图片缓存 ImageLoader.getInstance() .loadImage( imageuri, new ImageLoadingListener() { @Override public void onLoadingStarted(String arg0, View arg1) { System.out.println("onLoadingStarted"); } @Override public void onLoadingFailed(String arg0, View arg1, FailReason arg2) { System.out.println("onLoadingFailed"); } @Override public void onLoadingComplete(String arg0, View arg1, Bitmap drawable) { System.out.println("onLoadingComplete:" + drawable); Message msg = new Message(); msg.what = 1; msg.obj = drawable; handler.sendMessage(msg); } @Override public void onLoadingCancelled(String arg0, View arg1) { System.out.println("onLoadingCancelled"); } }); return null; } else { return null; } }
public void addBitMapToImage(table_interaction_news t_interaction_news, int j, int i) { LinearLayout item_layout = null; if (view_map.containsKey(t_interaction_news.getNews_id())) { item_layout = (LinearLayout) view_map.get(t_interaction_news.getNews_id()); System.out.println("view_map.containsKey-->" + t_interaction_news.getNews_id()); if (j == 0) { news_layout_01.removeView(item_layout); news_layout_01.addView(item_layout); } else if (j == 1) { news_layout_02.removeView(item_layout); news_layout_02.addView(item_layout); } } else { item_layout = (LinearLayout) inflater.inflate(R.layout.z_fragment_interaction_news_listview_item, null); ImageDownLoadAsyncTask imageTask = new ImageDownLoadAsyncTask(t_interaction_news, image_width); imageTask.setItem_layout(item_layout); imageTask.execute(); item_layout.setTag(String.valueOf(i)); item_layout.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getActivity(), "您点击了第" + v.getTag() + "个Item", Toast.LENGTH_SHORT) .show(); } }); if (j == 0) { news_layout_01.addView(item_layout); } else if (j == 1) { news_layout_02.addView(item_layout); } view_map.put(t_interaction_news.getNews_id(), item_layout); System.out.println("view_map.addKey-->" + t_interaction_news.getNews_id()); } }
@Override protected void onPostExecute(Bitmap drawable) { // TODO Auto-generated method stub super.onPostExecute(drawable); TextView news_title = (TextView) item_layout.findViewById(R.id.fragment_news_title_textview); TextView news_org = (TextView) item_layout.findViewById(R.id.fragment_news_org_textview); TextView news_time = (TextView) item_layout.findViewById(R.id.fragment_news_date_textview); TextView news_content = (TextView) item_layout.findViewById(R.id.fragment_news_content_textview); TextView zan_count = (TextView) item_layout.findViewById(R.id.fragment_news_zan_count_textview); TextView comment_count = (TextView) item_layout.findViewById(R.id.fragment_news_comment_count_textview); TextView share_count = (TextView) item_layout.findViewById(R.id.fragment_news_share_count_textview); TextView collect_count = (TextView) item_layout.findViewById(R.id.fragment_news_collect_count_textview); news_title.setText(t_interaction_news.getNews_title()); news_org.setText(t_interaction_news.getNews_org_name()); news_time.setText(t_interaction_news.getPublish_time()); String content_str = ""; if (t_interaction_news.getNews_content() != null && t_interaction_news.getNews_content().length() > 0) { if (t_interaction_news.getNews_content().length() > 23) { content_str = t_interaction_news.getNews_content().substring(0, 20) + "..."; } else { content_str = t_interaction_news.getNews_content(); } } news_content.setText(content_str); zan_count.setText(t_interaction_news.getPraise_count()); comment_count.setText(t_interaction_news.getComment_count()); share_count.setText(t_interaction_news.getShare_count()); collect_count.setText(t_interaction_news.getCollect_count()); }