I am unsure how to get alternating rows inflated for a listview
with a custom adapter in a sort of conversation style, that is user1
gets row_style1
and user2
gets row_style2
for their messages respectively. I have the data for both users in the same JSON object
. I was looking for help as to how best I can get this accomplished. I am not merely trying to get alternating views, but rather for every message user1 sends it always uses row_style1
and for every message user2
has row_style2
. If user1
sends 3 messages row_style1
is used for each of those, etc...
public class MsgAdapter extends ArrayAdapter<String> {
private ArrayList<String> memName,memAvatar,msgBody,msgTime;
private ArrayList<Integer> memId;
private LayoutInflater inflater;
private ImageLoader imageLoader;
public MsgAdapter(Context context, int resId, ArrayList<String> body, ArrayList<String> avatar, ArrayList<String> name,ArrayList<Integer> memId, ArrayList<String> msgTime, LayoutInflater inflater){
super(context,resId, body);
this.msgBody = body;
this.memName = name;
this.memAvatar = avatar;
this.msgTime = msgTime;
this.memId = memId;
this.inflater = inflater;
this.imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return super.getCount();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView == null){
v = inflater.inflate(R.layout.msg_thread_row_sender, parent, false);
}else
v = convertView;
TextView msg = (TextView)v.findViewById(R.id.msgBody);
TextView dateInfo = (TextView)v.findViewById(R.id.msgTime);
ImageView memImg = (ImageView) v.findViewById(R.id.usrImg);
imageLoader.DisplayImage(memAvatar.get(position), memImg);
msg.setText(msgBody.get(position));
dateInfo.setText(msgTime.get(position));
return v;
}
}