Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同时添加send和recive自定义消息样式时,其中一个无效 #157

Closed
china-coder opened this issue Nov 28, 2017 · 10 comments
Closed

Comments

@china-coder
Copy link

My environment:

同时添加自定义消息样式时,其中一个无效,必须要注释掉第一个,第二个才起作用,否则第二个显示为文本的样式。

@KenChoi1992
Copy link
Contributor

@china-coder 你怎么做的

@china-coder
Copy link
Author

china-coder commented Nov 28, 2017

自定义的holder
private static class DefaultLogSendViewHolder extends LogViewHolder {
public DefaultLogSendViewHolder(View itemView, boolean isSender) {
super(itemView, isSender);
}
}

// Use default layout
    MsgListAdapter.HoldersConfig holdersConfig = new MsgListAdapter.HoldersConfig();
    mAdapter = new MsgListAdapter<>("0", holdersConfig, imageLoader);
    //添加自定义类型
     CustomMsgConfig config1 = new CustomMsgConfig(14, R.layout.item_log_receive_txt, false, DefaultLogSendViewHolder.class);
    CustomMsgConfig config2 = new CustomMsgConfig(15, R.layout.item_log_send_text, true, DefaultLogSendViewHolder.class);
    // 第一个参数为 ViewType,同上
      mAdapter.addCustomMsgType(14, config1);
    mAdapter.addCustomMsgType(15, config2);
    MyMessage message3 = new MyMessage("haha1", IMessage.MessageType.RECEIVE_CUSTOM);
     message3.setUserInfo(new DefaultUser("1", "Ironman1", "R.drawable.ironman"));
     message3.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
     message3.setType(14);
     mAdapter.addToStart(message3, true);
    MyMessage message4 = new MyMessage("haha2", IMessage.MessageType.SEND_CUSTOM);
    message4.setUserInfo(new DefaultUser("2", "Ironman2", "R.drawable.ironman"));
    message4.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
    message4.setType(15);
    mAdapter.addToStart(message4, true);

@KenChoi1992
Copy link
Contributor

KenChoi1992 commented Nov 28, 2017

@china-coder 我知道了,是没有写上i

@china-coder
Copy link
Author

china-coder commented Nov 28, 2017

我看了一下源码,好像并没有对自定义的数组进行遍历,源码如下,使用的版本为0.5.4
for (int i=0; i < mCustomMsgList.size(); i++) {
CustomMsgConfig config = mCustomMsgList.valueAt(0);//这里并没有使用for循环的i值,永远只拿到第一个位置的值
if (message.getType().getCustomType() == config.getViewType()) {
return config.getViewType();
}
}

@china-coder
Copy link
Author

message的settype我按照文档上面的已经做了,如下
public void setType(int type) {
this.messageType.setCustomType(type);
}

@KenChoi1992
Copy link
Contributor

@china-coder 这个确实是个 bug,发布了新版本跟你说一声

@china-coder
Copy link
Author

okay think

@KenChoi1992
Copy link
Contributor

@china-coder 可以了,发布了 0.5.5 ,你再试试

@china-coder
Copy link
Author

好的,我试一试

@china-coder
Copy link
Author

可以了,谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants