I need to set up a simple event listener to refresh a ListView
once in a while. The problem is I don't know how could I generate an event.
I know that for events like key or button pressing I just need to implement the Handler
. But in this specific case I actually need to generate the event, which will be fired every time another running thread of my app wakes up and refreshes its list of news from an RSS feed.
I've done everything, but got stuck in here. Can I get any suggestion or link with some more info on how to implement this?
You can use android life cycle for that.
Create a signal interface, aka your event
Than register to it inside your activity or anywhere else you want, there could be many listeners to same
Signal
.And dispatch the signal when you need, from where ever you need.
Disclaimer: I am the author of android life cycle.
try this:
Define a callback interface
Provide a registration facility on the background thread which gets the RSS feed
Fire the callback when news is available
Register listener somewhere during initialization
It sounds like you need a Handler - (look-up android.os.Handler for details).
The sendMessageDelayed method will allow you to schedule when the message is sent to your handler.
A quick search pulled up a full example that should get you started: http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html