如何从PubNub方法历史记录()中输出ListView中的消息?

时间:2017-09-21 12:46:32

标签: java listview pubnub

我的项目(简单聊天应用程序)ListView of TextViews(消息)。这是发布消息的代码:

    public void publish(View view) {

    final EditText mMessage = (EditText) MainActivity.this.findViewById(R.id.new_message);

    final Map<String, String> message = ImmutableMap.<String, String>of("sender", MainActivity.this.nickName, "message", mMessage.getText().toString(), "timestamp", DateTimeUtil.getTimeStampUtc());
    MainActivity.this.mPubnub_DataStream.publish().channel(Constants.CHANNEL_NAME).shouldStore(true).message(message).async(
            new PNCallback<PNPublishResult>() {
                @Override
                public void onResponse(PNPublishResult result, PNStatus status) {
                    try {
                        if (!status.isError()) {
                            mMessage.setText("");
                            Log.v(TAG, "publish(" + JsonUtil.asJson(result) + ")");
                        } else {
                            Log.v(TAG, "publishErr(" + JsonUtil.asJson(status) + ")");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
    );
}

我正在尝试从历史输出消息:

this.mPubnub_DataStream.history()
                .channel(Constants.CHANNEL_NAME)
                .async(new PNCallback<PNHistoryResult>() {
                    @Override
                    public void onResponse(PNHistoryResult result, PNStatus status) {

                    }
                });

我不知道如何覆盖onResponse方法。请帮我。 顺便说一句,我可以检查我的消息是否存储,但输出到终端不是我真正需要的。

pubNub.history()
                .channel(channelName)
                .count(100)
                .async(new PNCallback<PNHistoryResult>() {
                    @Override
                    public void onResponse(PNHistoryResult result, PNStatus status) {
                        for (int i = 0; i < 100; i++) {
                            System.out.println(result.getMessages().get(i).getEntry());
                        }
                    }
                });

1 个答案:

答案 0 :(得分:0)

这是一个UI数据绑定问题,而不是PubNub问题,只要您实际接收来自历史记录调用的消息。

如果您可能是此示例应用程序中的示例代码可能会有所帮助:github.com/pubnub/webinar-android-intro

相关问题