in android i am trying to change the layout base on who the message is from. if the message is from me then display the layout mymessage.xml to the right else display message.xml to the left. i used if condition, but i don't know how to display one layout to the right and the second to the left,
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO
View messageView = null;
// Get a reference to the LayoutInflater. This helps construct the
// view from the layout file
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Change the layout based on who the message is from
if (messages.get(position).fromMe()) {
messageView = inflater.inflate(R.layout.mymessage , parent, false);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.mytimeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.mymessageTextView);
msgView.setText(messages.get(position).getMessage());
} else {
messageView = inflater.inflate(R.layout.message , parent, true);
//initialization of 2 textView, message and time
TextView timeView = (TextView) messageView.findViewById(R.id.timeTextView);
timeView.setText(messages.get(position).getTime());
TextView msgView = (TextView) messageView.findViewById(R.id.messageTextView);
msgView.setText(messages.get(position).getMessage());
}
return messageView;
}