public View getView( final int position, View convertView, final ViewGroup parent) { final ChatMsgEntity entity = coll.get(position); boolean isComMsg = entity.getMsgType(); ViewHolder viewHolder = null; if (convertView == null) { if (isComMsg) { convertView = mInflater.inflate( R.layout.chatting_item_msg_text_left, null); } else { convertView = mInflater.inflate( R.layout.chatting_item_msg_text_right, null); } viewHolder = new ViewHolder(); viewHolder.tvSendTime = (TextView) convertView .findViewById(R.id.tv_sendtime); viewHolder.tvUserName = (TextView) convertView .findViewById(R.id.tv_username); viewHolder.tvContent = (TextView) convertView .findViewById(R.id.tv_chatcontent); viewHolder.tvTime = (TextView) convertView .findViewById(R.id.tv_time); viewHolder.isComMsg = isComMsg; convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.tvSendTime.setText(entity.getDate()); if (entity.getText().contains(".amr")) { viewHolder.tvContent.setText(""); viewHolder.tvContent.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.chatto_voice_playing, 0); viewHolder.tvTime.setText(entity.getTime()); } else { viewHolder.tvContent.setText(entity.getText()); viewHolder.tvContent.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); viewHolder.tvTime.setText(""); } viewHolder.tvContent.setOnClickListener(new OnClickListener() { public void onClick(View v) { stopAudio(); if(pos != position){ //动态添加时 触发了下面的帧动画 ImageView imageView = (ImageView) parent.getChildAt(position).findViewById(R.id.tv_chatcontent_video); imageView.setImageResource(R.drawable.chat_anim); animationDrawable = (AnimationDrawable) imageView.getDrawable(); animationDrawable.start(); playMusic("http://192.168.1.61:9090/StarFile/JJJ/touch/sound/test_cbr.mp3"); pos = position; }else{ pos = -1; } } }); viewHolder.tvUserName.setText(entity.getName()); return convertView; } static class ViewHolder { public TextView tvSendTime; public TextView tvUserName; public TextView tvContent; public TextView tvTime; public boolean isComMsg = true; }
这是仿微信的一个adapter。
当播放声音的时候 需要显示一个帧动画。
现在的问题是当 播放声音时,可以正确显示帧动画,但是假如播放的时候,输入一条信息,则动画会显示在新输入的那条信息UI上。(注:onlick中的逻辑判断可能有问题,可以暂时忽略)
为什么新添加的item会触发onclick里的动画事件?
解决方案
20
可以尝试下。