在我的应用程序中,我去显示这样的消息
请告诉我,如何在列表视图中显示消息,以及如何显示列表视图,一个在左边,另一个在右边
以及如何在消息底部显示时间
请看我的代码
//view display
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AllmessagedispalyContants message = (AllmessagedispalyContants) this.getItem(position);
ViewHolder holder;
if(convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.allmessagesms, null);
holder.message = (TextView) convertView.findViewById(R.id.message_text);
holder.date=(TextView)convertView.findViewById(R.id.date);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.message.setText(message.getMessage());
holder.date.setText(message.getDate());
LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
lp = (LayoutParams)holder.date.getLayoutParams();
//check if it is a status message then remove background, and change text color.
if(message.isStatusMessage())
{
holder.message.setBackgroundDrawable(null);
lp.gravity = Gravity.LEFT;
holder.message.setTextColor(R.color.textFieldColor);
}
else
{
//Check whether message is mine to show green background and align to right
if(message.messageType.equals(bool))
{
holder.message.setBackgroundResource(R.drawable.right);
lp.gravity = Gravity.RIGHT;
}
//If not mine then it is from sender to show orange background and align to left
else
{
holder.message.setBackgroundResource(R.drawable.lift);
lp.gravity = Gravity.LEFT;
}
holder.message.setLayoutParams(lp);
holder.message.setTextSize(14);
Typeface typface=Typeface.createFromAsset(mContext.getAssets(),"fonts/Roboto-Bold.ttf");
holder.message.setTypeface(typface);
//holder.message.setTextColor(R.color.textColor);
}
return convertView;
}
private static class ViewHolder
{
TextView message;
TextView date;
}