I am trying to do a chat application. In my activity I have a ListView
and at bottom EditText
with a Button
"Send"
Like in chat after writing in EditText
and press the Send Button
the text will appear in ListView
. Two users are there. If the last user is same then that text should add to the previous list.
How can i do that ? here is my code below,
i don't want in this structure,
me: hi (after send button click)
me: hru (after send button click)
i want in this structure,
its taking two list item but i want
me: hi (after send button click)
h r u (after send button click)
friend: fine
Since you are trying to build chat kind of application, you should check transcript mode of listview too. check here,
http://www.mubasheralam.com/tutorials/android/listview-transcript-mode
public void sendMessage(String message)
{
messageAdapter.add("me :"+message);
messageAdapter.notifyDataSetChanged();
}
}
我没有看到您在 ArrayAdapter 上调用了 notifyDataSetChanged()。
setAdpater() .. method should be called after the new text is beeing added.. and the String[] array should be updated with new values..
or
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.