1)繼承EaseConversationListFragment
2)添加聯系人消息的監聽事件
// 監聽會話的變化 EMClient.getInstance().chatManager().addMessageListener(emMessageListener); private EMMessageListener emMessageListener = new EMMessageListener() { @Override public void onMessageReceived(List<EMMessage> list) { // 設置數據 EaseUI.getInstance().getNotifier().onNewMesg(list); // 刷新列表 refresh(); } @Override public void onCmdMessageReceived(List<EMMessage> list) { } @Override public void onMessageReadAckReceived(List<EMMessage> list) { } @Override public void onMessageDeliveryAckReceived(List<EMMessage> list) { } @Override public void onMessageChanged(EMMessage emMessage, Object o) { } };
3)會話條目的點擊事件
// 條目添加事件的監聽 setConversationListItemClickListener(new EaseConversationListItemClickListener() { @Override public void onListItemClicked(EMConversation conversation) { Intent intent = new Intent(getActivity(), ChatActivity.class); // 參數 intent.putExtra(EaseConstant.EXTRA_USER_ID, conversation.conversationId()); // 當前會話類型為群聊 if(conversation.getType() == EMConversation.EMConversationType.GroupChat) { intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE,EaseConstant.CHATTYPE_GROUP); } getActivity().startActivity(intent); } }); // 清空當前會話列表數據,准備加載新的數據 conversationList.clear();