這次主要實現了聊天記錄列表的adapter,即上次的msgrecyclerview的adapter,主要是各類訊息的左右顯示和各條訊息的頭像設定。
1.通過訊息的msgdirectionenum和msgtypeenum屬性(網易雲信提供),確定訊息的顯示位置和方式。
private int getmsgviewtype(msgdirectionenum direct, msgtypeenum type) else if (type == msgtypeenum.image) else if (type == msgtypeenum.audio) else if (type == msgtypeenum.location) else
} else else if (type == msgtypeenum.image) else if (type == msgtypeenum.audio) else if (type == msgtypeenum.location) else
}}
private static final int msg_text_l = 0x20000;
private static final int msg_img_l = 0x20001;
private static final int msg_audio_l = 0x20002;
private static final int msg_video_l = 0x20003;
private static final int msg_loc_l = 0x20004;
private static final int msg_text_r = 0x30000;
private static final int msg_img_r = 0x30001;
private static final int msg_audio_r = 0x30002;
private static final int msg_video_r = 0x30003;
private static final int msg_loc_r = 0x30004;
2.recycleview 的adapter的oncreateviewholder、onbindviewholder以及getitemcount
@override
public rviewholder oncreateviewholder(viewgroup parent, int layoutid)
@override
public void onbindviewholder(rviewholder holder, int position) else
}@override
public int getitemcount()
其中用到的bindmsgview方法:包括頭像設定、process bar的顯示、根據型別繫結資料
private void bindmsgview(final rviewholder holder, final immessage message)
});} else
// 根據訊息狀態和附件傳輸狀態決定是否顯示progress bar
if (mchatutils.istransferring(message)) else
// 根據型別繫結資料
int viewtype = getmsgviewtype(message.getdirect(), message.getmsgtype());
switch (viewtype)
}});
break;
// 影象
case msg_img_l:
case msg_img_r:
imageattachment imageattachment = (imageattachment) message.getattachment();
final selectableroundedimageview imageview = (selectableroundedimageview)
holder.getimageview(r.id.iv_msg_img);
bitmap bitmap = mchatutils.getbitmap(imageattachment);
if (bitmap != null)else
imageview.setonclicklistener(new view.onclicklistener()
}});
break;
// 音訊
case msg_audio_l:
case msg_audio_r:
audioattachment audioattachment = (audioattachment) message.getattachment();
holder.settext(r.id.tv_audio_time, mchatutils.getaudiotime(audioattachment.getduration()));
relativelayout layout = holder.getreltivelayout(r.id.layout_audio_msg);
mchatutils.setaudiolayoutwidth(layout, audioattachment.getduration());
holder.getreltivelayout(r.id.layout_audio_msg)
.setonclicklistener(new view.onclicklistener()
}});
break;
// 位置
case msg_loc_l:
case msg_loc_r:
locationattachment locationattachment = (locationattachment) message.getattachment();
holder.settext(r.id.tv_loc_address,locationattachment.getaddress());
holder.gettextview(r.id.tv_show_loc).setonclicklistener(new view.onclicklistener()
}});
break;
}}
3.重寫的recyclerview.adapter的getitemviewtype方法:
@override
public int getitemviewtype(int position) else
}
private int getviewlayoutid(int viewtype)
}
4.public messagelistadapter(context context, listmessages, chatsession session)
實訓第七天
姓名 祖東科 日期 2018.7.15 作業training4 字串訓練 1.題目 請編寫乙個c函式,該函式將乙個字串逆序 include include include int main scanf s ptr begin ptr ptr strlen ptr 1 while ptr begin ...
創新實訓第七章
今天本來是打算把主介面設計好的,但是我做了好幾個設計方案都感覺並不滿意,總是感覺好像不好看,但是還是硬著頭皮做了一部分 其實我本身試了好幾種方案,從早晨做到晚上,但是還是刪了又寫寫了又刪,總是感覺做的不咋地,真是難受。到最後差不過就做了這些。然後中間還遇到了很多的問題。還有絕對布局相對布局的問題,這...
校內實訓第七天學習筆記
通過ip實現今天天氣及未來七天天氣的展示 先通過設定ip實現api接入,修改函式得到當前定位的天氣。對頁面總體布局進行設定,實現滑動顯示七天天氣。js設定自動獲取定位,顯示本地地區 wx獲取位置介面 wx.getlocation success function res 設定接入今日天氣和七天天氣的...