예제 #1
0
  public int getItemViewType(int position) {
    ChatMsgEntity entity = chatLists.get(position);

    if (entity.getMsgType()) {
      return IMsgViewType.IMVT_COM_MSG;
    } else {
      return IMsgViewType.IMVT_TO_MSG;
    }
  }
예제 #2
0
  public View getView(int position, View convertView, ViewGroup parent) {

    final ChatMsgEntity entity = chatLists.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) {
            if (entity.getText().contains(".amr")) {
              playMusic(
                  android.os.Environment.getExternalStorageDirectory() + "/" + entity.getText());
            }
          }
        });
    viewHolder.tvUserName.setText(entity.getName());

    return convertView;
  }