Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 42
Registered: ‎12-04-2008
My Device: Not Specified

How to refresh list?

I have a list field to display some contacts information.But if the information is modified somewhere outside the application,

I wonder how can I refresh the information in the list field.Any suggestion will be appreciated.Thanks in advance.Smiley Happy

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to refresh list?

A common way to do this is to implement the Observer pattern.

 

The Screen class registers a listener with the "model" (the data class), and is notified whenever a change in the data occurs.

 

This type of mechanism is used in MVC implementations.

 

 

Developer
Posts: 42
Registered: ‎12-04-2008
My Device: Not Specified

Re: How to refresh list?

Any code example or any api I can use?
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: How to refresh list?

Check this link: MVC Pattern

 

There are examples according to Java 2 Standard Edition, but it does not matter. The main point - is the approach.

Use the same approach in your application.

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to refresh list?

A simple implementation would be to create an interface, like this:

 

public interface DataListener { public void dataEvent(DataEvent event); }

 

 

You will implement this interface in your Screen class that displays the list.

 

Then you will add this listener to your Model class (the class that is managing the data):

 

Inside the model class, you will implement:

public void addDataListener(DataListener listener) { if (m_listeners.contains(listener) == false){ m_listeners.addElement(listener); } }

 

Where m_listeners is a vector containing all the listeners registered with this model.

 

Now, when a change occurs in the data, you will fire the data event:

 

 

protected void fireDataEvent(DataEvent event) { DataListener listener; for (int i = 0; i < m_listeners.size(); i++){ listener = (DataListener) m_listeners.elementAt(i); listener.dataEvent(event); } }

 

 

 

This should give you a start!