简体   繁体   中英

Update ListView on UI on receiving Broadcast intent

I have a list of items on the UI. When the app catches an intent with a BroadCastReceiver , I need to update a specific item in the list (hide an ImageView on the item row). The list uses a custom adapter obviously. How can I do that?

I tried access the fragment where is the ListView using the Application object called from the receiver, but Android gave me this error:

"Only the original thread that created a view hierarchy can touch its views"

Sorry if I'm a bit generic, but I don't know which part of the code provide, actually.

I'm guessing that you're trying to edit the list from another thread that received this Broadcast. if indeed this is the case there is a simple solution - the Activity class supplies a method called - runOnUiThread. You can see an example on this post : Android “Only the original thread that created a view hierarchy can touch its views.

Good Luck!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM