1
我正在创建一个聊天应用程序。当我从服务器获得新聊天时,我通过向列表中添加最后一行来更新列表。但是,一旦我发送消息,我将它添加到列表中。当消息发送时,我从服务器获得成功响应。我需要在列表的最后一行更新成功消息而不添加新行。如何更新listview android的最后一行?
我贴的代码块从适配器类
@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. Don't add new row
}else if(msg.equals("Not Seen")) {
// need to change the status here. Don't add new row
} else if(msg.equals("Received message")){
// need to change the status here. Don't add new row
} else {
// else add new row and add new chat message
}
return view;
}
任何人都可以给我一个解决方案吗?
notifyDataSetChanged不适用于更新工作。适用于添加/删除。 –
在适配器改变后,它会被调用。 –