插入右侧
插入的\u左
我在应用程序中向自己发送一条消息,因为它应该显示为以绿色气泡发送消息,然后在下面以左侧(蓝色气泡)接收消息。
但在上面的图像中,消息显示在固定的位置,就像我发送消息时一样,发送消息显示在右上角(绿色气泡),接收到的消息显示在下面(蓝色气泡)
提前谢谢
我要把它当作
you2
你2
当我再次发送信息时,它应该显示为
you3
你3
you4
你4
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);
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!