Created
December 16, 2012 15:04
AwesomeAdapter is used to show speech bubble in ListView as row.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
Message message = (Message) this.getItem(position); | |
ViewHolder holder; | |
if(convertView == null) | |
{ | |
holder = new ViewHolder(); | |
convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false); | |
holder.message = (TextView) convertView.findViewById(R.id.message_text); | |
convertView.setTag(holder); | |
} | |
else | |
holder = (ViewHolder) convertView.getTag(); | |
holder.message.setText(message.getMessage()); | |
LayoutParams lp = (LayoutParams) holder.message.getLayoutParams(); | |
//Check whether message is mine to show green background and align to right | |
if(message.isMine()) | |
{ | |
holder.message.setBackgroundResource(R.drawable.speech_bubble_green); | |
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.speech_bubble_orange); | |
lp.gravity = Gravity.LEFT; | |
} | |
holder.message.setLayoutParams(lp); | |
holder.message.setTextColor(R.color.textColor); | |
return convertView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment