插入右
inserted_left
我在应用程序中向自己发送消息,因为它应该显示为以绿色气泡发送消息然后在下面收到消息为左(蓝色气泡)。
但是在上面的图像中,消息显示在固定的位置 每当我发送消息时,发送消息出现在右上角(绿色气泡) 和收到的消息如下(蓝色气泡)
提前致谢
you2
you2
当我再次发送消息时,它应显示为
you3
you3
you4
you4
chatlistAdapter.java
public class chatList_AdapterClass extends BaseAdapter {
private Context mContext;
private ArrayList<chatList_row> mArrayList;
ViewHolder mHolder=null;
public chatList_AdapterClass(Context context, ArrayList<chatList_row> arrayList) {
mContext = context;
mArrayList = arrayList;
}
public class ViewHolder{
TextView mReceivedMessage;
LinearLayout.LayoutParams mParams;
ViewHolder(View v){
mReceivedMessage=(TextView)v.findViewById(R.id.ChatListMessages);
}
}
@Override
public int getCount() {
return mArrayList.size();
}
@Override
public Object getItem(int i) {
return mArrayList.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View ConvertView, ViewGroup parent) {
View row=ConvertView;
if (row == null){
LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.chat_list_row,parent,false);
mHolder=new ViewHolder(row);
mHolder.mParams=(LinearLayout.LayoutParams)mHolder.mReceivedMessage.getLayoutParams();
row.setTag(mHolder);
}else {
mHolder=(ViewHolder)row.getTag();
}
mHolder.mReceivedMessage.setText(mArrayList.get(position).getMessageContent());
boolean send=mArrayList.get(position).getTypeofMessage().equals("send");
setChatRowAppearance(send,mHolder);
return row;
}
public void setChatRowAppearance(boolean send,ViewHolder mHolder){
if (send){
mHolder.mParams.gravity= Gravity.END;
mHolder.mReceivedMessage.setTextColor(Color.WHITE);
mHolder.mReceivedMessage.setBackgroundResource(R.drawable.bubble2);
}else {
mHolder.mParams.gravity= Gravity.START;
mHolder.mReceivedMessage.setTextColor(Color.WHITE);
mHolder.mReceivedMessage.setBackgroundResource(R.drawable.bubble1);
}
}
}