@Override public void handleMessage(Message msg) { switch (msg.what) { case MsgTagVO.MSG_LIKE: { if (JsonHandler.checkResult((String) msg.obj, mContext)) { CommonUtil.displayToast(mContext, R.string.label_zanSuccess); Bundle bundle = msg.getData(); String id = bundle.getString("data"); for (ZhuoInfoVO item : mList) { if (id != null && id.equals(item.getMsgid())) { item.setGoodnum((Integer.valueOf(item.getGoodnum()) + 1) + ""); break; } } notifyDataSetChanged(); } break; } case MsgTagVO.MSG_DEL: { if (JsonHandler.checkResult((String) msg.obj, mContext)) { CommonUtil.displayToast(mContext, R.string.info12); Bundle bundle = msg.getData(); String id = bundle.getString("data"); for (ZhuoInfoVO item : mList) { if (id != null && id.equals(item.getMsgid())) { mList.remove(item); break; } } notifyDataSetChanged(); } } } }
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.item_zhuoinfo_list, null); holder = initHolder(convertView); convertView.setTag(R.id.tag_view_holder, holder); } else { holder = (ViewHolder) convertView.getTag(R.id.tag_view_holder); } ZhuoInfoVO zhuoinfo = mList.get(position); String id = zhuoinfo.getMsgid(); UserVO user = zhuoinfo.getUser(); String uid = user.getUserid(); String company = user.getCompany(); String authorName = user.getUsername(); String headUrl = user.getUheader(); String work = user.getPost(); String type = zhuoinfo.getType(); String category = zhuoinfo.getCategory(); String title = zhuoinfo.getTitle(); String detail = zhuoinfo.getText(); convertView.setTag(R.id.tag_id, id); convertView.setTag(R.id.tag_string, type); holder.nameTV.setText(authorName); String woco = ZhuoCommHelper.concatStringWithTag(work, company, "|"); if (woco.length() > 1) { holder.workTV.setText(woco); holder.workTV.setVisibility(View.VISIBLE); } else { holder.workTV.setText(""); holder.workTV.setVisibility(View.GONE); } if (type != null && !type.equals("")) { Map<String, Object> resinfo = ZhuoCommHelper.gentResInfo(type, category, title, detail, mContext); holder.resIV.setImageResource((Integer) resinfo.get("ico")); String text = (String) resinfo.get("category") + (String) resinfo.get("title") + (String) resinfo.get("content"); holder.resTV.setText(text); Rect bounds = new Rect(); TextPaint paint = holder.resTV.getPaint(); paint.getTextBounds(text, 0, text.length(), bounds); int width = bounds.width(); if (width / (this.width - 81 * times) > 4) { holder.moreTV.setVisibility(View.VISIBLE); } else { holder.moreTV.setVisibility(View.GONE); } } else { holder.resIV.setImageResource(0); holder.resTV.setText(""); } holder.resTV.setMaxLines(4); holder.moreTV.setText(R.string.info1); holder.tl.removeAllViews(); holder.headIV.setImageResource(R.drawable.default_userhead); holder.headIV.setTag(headUrl); mLoadImage.addTask(headUrl, holder.headIV); final List<PicVO> pics = zhuoinfo.getPic(); RelativeLayout.LayoutParams layoutParams = holder.rlp; if (pics != null && pics.size() == 1) { layoutParams = holder.rlp2; } if (pics != null && pics.size() > 0) { TableRow tr = null; for (int i = 0; i < pics.size(); i++) { if (i % 3 == 0) { tr = new TableRow(mContext); holder.tl.addView(tr); } tr.setLayoutParams(holder.tllp); RelativeLayout rl = new RelativeLayout(mContext); rl.setLayoutParams(holder.trlp); ImageView iv = new ImageView(mContext); iv.setLayoutParams(layoutParams); rl.addView(iv); rl.setTag(pics.get(i).getOrgurl()); iv.setTag(pics.get(i).getUrl()); iv.setImageResource(R.drawable.default_image); mLoadImage.addTask(pics.get(i).getUrl(), iv); rl.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, PhotoViewMultiActivity.class); ArrayList<String> orgs = new ArrayList<String>(); for (int j = 0; j < pics.size(); j++) { orgs.add(pics.get(j).getOrgurl()); } intent.putStringArrayListExtra("pics", orgs); intent.putExtra("pic", (String) v.getTag()); mContext.startActivity(intent); } }); tr.addView(rl); } } String place = zhuoinfo.getPosition(); if (null == place) { place = ""; } String time = zhuoinfo.getAddtime(); time = CommonUtil.calcTime(time); holder.timeTV.setText(time + " " + place); if (myid.equals(uid)) { holder.delTV.setVisibility(View.VISIBLE); } else { holder.delTV.setVisibility(View.GONE); } List<String> tags = zhuoinfo.getTags(); if (tags != null && tags.size() > 0) { String tagStr = " "; for (String tag : tags) { tagStr += tag + " "; } holder.tagTV.setText(tagStr); holder.relativeLayoutTag.setVisibility(View.VISIBLE); } else { holder.relativeLayoutTag.setVisibility(View.GONE); } String cmtNum = zhuoinfo.getCmtnum(); String goodNum = zhuoinfo.getGoodnum(); String collectNum = zhuoinfo.getCollectnum(); String zfNum = zhuoinfo.getForwardnum(); if (null == cmtNum || cmtNum.equals("")) { cmtNum = "0"; } if (null == goodNum || goodNum.equals("")) { goodNum = "0"; } if (null == collectNum || collectNum.equals("")) { collectNum = "0"; } if (null == zfNum || zfNum.equals("")) { zfNum = "0"; } holder.goodNumTV.setText(goodNum); holder.cmtNumTV.setText(cmtNum); holder.zfNumTV.setText(zfNum); holder.collectNumTV.setText(collectNum); List<CmtVO> cmts = zhuoinfo.getCmt(); if (cmts != null && cmts.size() > 0) { holder.layoutGongXuCmt.setBackgroundResource(R.drawable.shape_gray_corners); for (CmtVO msg : cmts) { LinearLayout layoutCmtOne = new LinearLayout(mContext); layoutCmtOne.setLayoutParams(holder.layoutParams); layoutCmtOne.setOrientation(LinearLayout.HORIZONTAL); TextView userTv = new TextView(mContext); userTv.setLayoutParams(holder.layoutParams); userTv.setTextColor(0xff41546d); TextView contentTV = new TextView(mContext); contentTV.setLayoutParams(holder.layoutParams); UserVO cmtUser = msg.getUser(); String uname = cmtUser.getUsername(); String userid = cmtUser.getUserid(); String msgContent = msg.getContent(); userTv.setText(uname + ":"); contentTV.setText(msgContent); layoutCmtOne.addView(userTv); layoutCmtOne.addView(contentTV); layoutCmtOne.setTag(userid); holder.layoutGongXuCmt.addView(layoutCmtOne); } } initEvent(holder, convertView, id, uid); mLoadImage.doTask(); return convertView; }