【问题标题】:Chat app - updating last row聊天应用程序 - 更新最后一行
【发布时间】:2014-03-10 17:53:10
【问题描述】:

我正在创建一个聊天应用程序。当我从服务器获得新聊天时,我正在通过将最后一行添加到列表来更新列表。但是,一旦我发送消息,我就会将其添加到列表中。发送消息时,我收到来自服务器的成功响应。我需要更新列表最后一行中的成功消息而不添加新行。

我正在粘贴适配器类中的代码块

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (type == TYPE_MESSAGE) {
        view = inflater.inflate(R.layout.message_list_view, null);
        if(msg.equals("Seen")) {
        // need to change the status here. Dont add new row
        return view;
    }else if(msg.equals("Not Seen")) {
        // need to change the status here. Dont add new row

        return view;
    } else if(msg.equals("Received message")){
        // need to change the status here. Dont add new row     
        return view;
    } else {
        // else add new row and add new chat message
    }
    return view;
}

谁能给我一个解决方案?

提前致谢。 Sundeep.S.

【问题讨论】:

    标签: android listview chat


    【解决方案1】:

    更新您在列表中使用的现有消息对象,并通知列表适配器数据集更改如下:

    YourCrazyAdapter adapter = ((YourCrazyAdapter) listView.getAdapter());
    adapter.notifyDataSetChanged();
    

    【讨论】:

      【解决方案2】:

      由于没有提供任何来源,我只能尝试指导你喜欢

      首先选择最后一项并设置更新其值。然后调用yourAdapter.setNotifyDatasetChanged() 就完成了。

      【讨论】:

      • 我需要从适配器更新它。我可以在侧适配器中使用 setNotifyDatasetChanged() 吗?
      猜你喜欢
      • 2023-02-25
      • 2018-12-28
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多