我有群组聊天,我想标记特定消息(isProducer
为true
时发送的消息)。问题是它将所有消息全部标记在一起......
这是我的Adapter
代码:
if(customer_id.equals(message.getUserId()))
isMe = true;
if(message.getUserId().equals(producer_id))
isProducer = true;
if (isMe) {
holder.imageRight.setVisibility(View.VISIBLE);
holder.imageLeft.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
} else {
holder.imageLeft.setVisibility(View.VISIBLE);
holder.imageRight.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
}
holder.body.setText(message.getBody());
if (isProducer) {
holder.body.setTypeface(null, Typeface.BOLD);
}
日Thnx!
答案 0 :(得分:0)
if(customer_id.equals(message.getUserId()))
isMe = true;
if(message.getUserId().equals(producer_id))
isProducer = true;
if (isMe) {
holder.imageRight.setVisibility(View.VISIBLE);
holder.imageRight.setbackground(R.drawable.rightimg);
holder.imageLeft.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
} else {
holder.imageLeft.setVisibility(View.VISIBLE);
holder.imageRight.setbackground(R.drawable.leftimg);
holder.imageRight.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
}
holder.body.setText(message.getBody());
if (isProducer) {
holder.body.setTypeface(null, Typeface.BOLD);
}
}
你可以用户R.drawable.leftimg和R.drawable.rightimg应该是ninepatch image
答案 1 :(得分:0)
试试这个
isMe = customer_id.equals(message.getUserId());
isProducer = message.getUserId().equals(producer_id);
if (isMe) {
holder.imageRight.setVisibility(View.VISIBLE);
holder.imageLeft.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
} else {
holder.imageLeft.setVisibility(View.VISIBLE);
holder.imageRight.setVisibility(View.GONE);
holder.body.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
}
holder.body.setText(message.getBody());
if (isProducer) {
holder.body.setTypeface(null, Typeface.BOLD);
} else {
holder.body.setTypeface(null, Typeface.NORMAL); // Or anything else
}