Dec 10 |
3:50 PM |
Mark M. |
has entered the room |
Mark M. |
turned on guest access |
Dec 10 |
4:00 PM |
EGHDK |
has entered the room |
Mark M. |
hello, EGHDK!
|
Mark M. |
how can I help you today?
|
EGHDK |
Hey Mark! So, I have an interesting problem. I have a listView and at the bottom I have an editText and a button. I am making a chat client.
|
EGHDK |
When I press send, the message sends, and shows up on my other phone, but it doesn't show up on the phone that I originally sent it from, until I "hide the keyboard" or if I leave the convo, and I come back.
|
EGHDK |
Any quick thoughts on why it might not be updating the listview right away?
|
Mark M. |
what are you doing to update the ListView?
|
Dec 10 |
4:05 PM |
EGHDK |
Well, in my on resume I'm doing adapter.notifyDatasetChanged
|
Mark M. |
what is the base class for your ListAdapter? ArrayAdapter? BaseAdapter? something else?
|
EGHDK |
ArrayAdapter
|
Mark M. |
how are you adding new entries to the ArrayAdapter? are you calling add() or insert() on the ArrayAdapter? or are you calling methods on the ArrayList?
|
Dec 10 |
4:10 PM |
EGHDK |
Im not sure?
|
Mark M. |
well, your ArrayAdapter does not get updated by out of work Keebler elves :-)
|
EGHDK |
Sorry. I'm trying to look through my code, but I don't see myself calling add or insert anywhere in my adapter.
|
Mark M. |
when the user clicks Send, you must be doing something with the entered text, besides whatever networking stuff you are doing to send it to the other phone
|
Mark M. |
unless you are not showing your own chat messages until you receive them from a chat room
|
EGHDK |
I'm adding it to the array of messages.
|
Mark M. |
so, you are adding it to the ArrayList?
|
EGHDK |
I'm using an ArrayAdapter of a type of object I created called Messages
|
EGHDK |
Yeah, I'm just adding to it.
|
Mark M. |
ideally, get rid of notifyDataSetChanged(), and to call add() or insert() on the ArrayAdapter, rather than calling one of those on the ArrayList
|
Dec 10 |
4:15 PM |
Mark M. |
calling add(), insert(), or remove() on the ArrayAdapter both updates the ArrayList *and* does a notifyDataSetChanged() for you
|
EGHDK |
How convenient. Thanks!
|
Mark M. |
and, since it does notifyDataSetChanged() right away, your ListView will update right away
|
Mark M. |
waiting until onResume() to fire notifyDataSetChanged() yourself is probably the source of your delay
|
EGHDK |
I'm sure that will solve it. Time to go eat! Stay warm if you are getting hit by snow by you! Hahaha. Thanks again!
|
Mark M. |
snow's passed, already did my shoveling
|
Dec 10 |
4:20 PM |
EGHDK |
has left the room |
Dec 10 |
4:55 PM |
Mark M. |
turned off guest access |