BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Refreshing the screen not working (http://www.blackberryforums.com/developer-forum/233700-refreshing-screen-not-working.html)

romah 08-17-2010 10:51 AM

Refreshing the screen not working
 
Refreshing the screen not working

Code:

public class MyScreen extends MainScreen{
private Timer headerTimer = new Timer();
private TimerTask headerTask;
 
public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
objList=srv.getList();//calls webmethod getList()
myMgr.add(objList)
add(myMgr);

headerTask= new TimerTask() {

public void run() {

 //doPaint();

 invalidate();
}
};

 headerTimer.scheduleAtFixedRate(headerTask, 3000, 3000);
}
}

There is no problem in displaying the data from the database. I am trying to refresh this screen data in every 3 seconds so that if any data change in database also reflect in this screen. But it doesn't work.

Also this screen is pushed from another screen using
net.rim.device.api.ui.UiApplication.getUiApplicati on().pushScreen(new MyScreen());

Please someone help me.

Dougsg38p 08-17-2010 11:56 AM

You cannot access the UI classes from a non-event thread (as you are doing here). The UI is non re-entrant.

Look at UiApplication.invokeLater() - this places your UI method calls in the event queue.

romah 08-17-2010 02:27 PM

How to define 3 seconds time interval in UiApplication.invokeLater() so that it refreshs the screen repeatedly?

UiApplication.getUiApplication().invokeLater (new Runnable() {
public void run()
{
//Thread.sleep(3000);
invalidate();
}
});

romah 08-17-2010 02:57 PM

I also tried with following code. Again, it's not working.

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
invalidate();
}
},3000,true);

Dougsg38p 08-17-2010 05:15 PM

What are you invalidating? If you are adding items to a listfield (for example) then you should be invalidating the list field.

Looks like you are trying to invalidate the screen here.

romah 08-18-2010 02:40 PM

I added the object list in Manager and that mananger to the screen.
I tried invalidating the manager. Again it's not refreshing the screen data.

public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
ObjectListField objList=srv.getList();//calls webmethod getList()
myMgr.add(objList)
add(myMgr);

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
myMgr.invalidate();
}
},3000,true);
}

romah 08-18-2010 04:20 PM

Now the refresh is working fine but throws exception while assigning the value to the manager in run().

public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();

myMgr=displayInfo();
add(myMgr);

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {

//invalidate();
myMgr=displayInfo();
myMgr.invalidate();
}
},3000,true);
}

public VerticalFieldManager displayInfo() {

VerticalFieldManager test=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
ObjectListField objList=srv.getList();//calls webmethod getList()
test.add(objList)

retrun test;

}

Dougsg38p 08-18-2010 05:01 PM

I don't understand this code:

VerticalFieldManager myMgr=new VerticalFieldManager();
myMgr=displayInfo();

Why would you set myMgr to one value, then set it to another on the next line?

Then again:

myMgr=displayInfo();
myMgr.invalidate();

What is the point of assigning this variable yet again?

Exactly what line of code is throwing the exception?

My opinion, you need to rethink what you are doing here (either that, or I'm an idiot because I don't understand your code).

..could go either way... :)

romah 08-19-2010 09:01 AM

Code:

VerticalFieldManager myMgr=new VerticalFieldManager();
myMgr=displayInfo();
add(myMgr);

In above code, displayInfo() calls webmethod, populates the list with database values, adds the list in manager and returns manager which contains that list.
I assigned return value of displayInfo() to the another manager. And after that I added the manager to the screen.
This portion works fine for me.

I want to refresh the list in the manger in every 3 seconds. So, I tried to populate the manager with new values and invalidate the manager. But their is problem in assigning the return value of displayInfo() in the manager.

myMgr=displayInfo(); line throws exception [IllegalArgumentException] in code below.

Code:

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
myMgr=displayInfo();
myMgr.invalidate();
}
},3000,true);
}


romah 08-19-2010 09:15 AM

Woked fine !!! Solved !!!
Thank you Dougsg38p for helping me.

Code:

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
delete(myMgr);
myMgr=displayInfo();
add(myMgr);
myMgr.invalidate();
}
},3000,true);


Dougsg38p 08-19-2010 09:15 AM

The issue is not in the assignment of the value to myMgr.

Have you single-stepped the code to see where the error really is? Have you looked at the stack trace?

My guess is that you are adding the same field to the display twice, which would cause this error. There should be text assoicated wtih the exception, like "child already parented", or something like this.

romah 08-19-2010 09:17 AM

Thank you Dougsg38p. It worked now.


All times are GMT -5. The time now is 04:41 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.