Apr 25 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 25 | 7:30 PM |
wuqiang | has entered the room |
wuqiang |
Hi , morning
|
wuqiang |
In china now is morning
|
wuqiang |
..... good afternoon
|
Mark M. |
hello, wuqiang!
|
Mark M. |
how can I help you today?
|
wuqiang |
View paste
(16 more lines)
|
Apr 25 | 7:35 PM |
Mark M. |
let me guess: you are having problems with notifyDataSetChanged()
|
wuqiang |
View paste
|
Mark M. |
you cannot call notifyDataSetChanged() on a background thread
|
Mark M. |
at least, assuming that restaurantAdapter is a ListAdapter of some form
|
Mark M. |
so, that little bit of work needs to be done on the main application thread
|
Mark M. |
there are many options for this
|
Mark M. |
I outline them in my chapter on threads
|
wuqiang |
it is a RecyclerView's Adapter
|
Mark M. |
I have not tried calling notifyDataSetChanged() on a RecyclerView.Adapter
|
Mark M. |
(on a background thread, that is)
|
Mark M. |
I would expect it to have the same problems as would ListView and a ListAdapter
|
Mark M. |
with a crash saying that you are modifying the views from a thread other than the thread that created them
|
Mark M. |
but, perhaps they added something to RecyclerView that handles this issue for you
|
Mark M. |
I do not know much about BmobQuery, BmobException, etc., so I do not know if you have any problems with that
|
Apr 25 | 7:40 PM |
Mark M. |
you are modifying the restaurants collection from a background thread, and presumably you are accessing it from the main application thread, so you would need to use some sort of synchronization there
|
Mark M. |
or, if you wind up moving notifyDataSetChanged() to the main application thread, update the restaurants collection on the main application thread as well
|
wuqiang |
and after annotating "restaurantAdapter.notifyDataSetChanged();" ,it doesn't work
|
wuqiang |
have noting to show
|
wuqiang |
and where should i put restaurantAdapter.notifyDataSetChanged(); in main Thread ?
|
Mark M. |
options for moving that code to the main application thread include: switching from Thread to AsyncTask, using post() on some view, using runOnUiThread() on your activity, and using an event bus
|
Mark M. |
I cover all of those in my chapter on threads in the book
|
Mark M. |
(pages 523-547 of Version 8.5 of the book)
|
Apr 25 | 7:45 PM |
wuqiang |
thanks
|
wuqiang |
let me have a look
|
wuqiang |
and i have no question today
|
wuqiang |
Thands a lot
|
wuqiang |
Thanks a lot
|
Mark M. |
happy to help!
|
Apr 25 | 8:20 PM |
Rick | has entered the room |
Apr 25 | 8:25 PM |
Mark M. |
hello, Rick!
|
Mark M. |
do you have a quick question?
|
Rick |
Hi! I did but my 3 year old is screaming. I'll have to try again next time.
|
Mark M. |
OK
|
Rick |
Thanks though.
|
Mark M. |
tell your 3-year-old that I said "shhh -- it'll be OK" :-)
|
Rick |
He doesn't know "shhh"
|
Rick |
Next office hour's when?
|
Mark M. |
Saturday at 4pm US Eastern
|
Rick |
okay, thank you
|
Apr 25 | 8:30 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will go up on https://commonsware.com/office-hours/
|
Mark M. |
have a pleasant day!
|
wuqiang | has left the room |
Rick | has left the room |
Mark M. | turned off guest access |