public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = inflater.inflate(resource, null); HashMap<String, Object> map = list.get(position); RoundImageView userimage = (RoundImageView) convertView.findViewById(R.id.comment_item_autohorImg); userimage.setImageBitmap((Bitmap) map.get("userimage")); TextView nickname = (TextView) convertView.findViewById(R.id.comment_item_authorName); nickname.setText(map.get("nickname").toString()); TextView createtime = (TextView) convertView.findViewById(R.id.comment_item_time); createtime.setText(map.get("createtime").toString()); TextView message = (TextView) convertView.findViewById(R.id.comment_item_content); CharSequence mtemp = null; try { mtemp = java.net.URLDecoder.decode(map.get("message").toString(), "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } message.setText(mtemp); TextView supportnum = (TextView) convertView.findViewById(R.id.comment_item_supportNum); supportnum.setText(map.get("supportnum").toString()); // commentcanzan ImageView commentcanzan = (ImageView) convertView.findViewById(R.id.comment_item_support); commentcanzan.setImageBitmap( PicUtil.readBitMap(context, Integer.parseInt(map.get("commentcanzan").toString()))); commentcanzan.setOnClickListener(new ButtonClick(position, convertView)); return convertView; }
public void onClick(View v) { // TODO Auto-generated method stub ImageView imageView = (ImageView) v; HashMap<String, Object> map = list.get(position); Integer integer = Integer.parseInt(map.get("commentcanzan").toString()); TextView supportnum = (TextView) convertView.findViewById(R.id.comment_item_supportNum); switch (integer) { case R.drawable.square_item_like: imageView.setImageBitmap(PicUtil.readBitMap(context, R.drawable.square_item_unlike)); integer = R.drawable.square_item_unlike; supportnum.setText(String.valueOf(Integer.parseInt(supportnum.getText().toString()) + 1)); postCommentLike(map.get("id").toString(), 1); break; default: imageView.setImageBitmap(PicUtil.readBitMap(context, R.drawable.square_item_like)); integer = R.drawable.square_item_like; supportnum.setText(String.valueOf(Integer.parseInt(supportnum.getText().toString()) - 1)); postCommentLike(map.get("id").toString(), 2); break; } list.get(position).put("commentcanzan", integer); }