12-25-2012 02:24 PM
Please, can any one help me on how to refresh screen.
12-25-2012 09:13 PM
Normall when we cal/use invalidate() method it calls the paint() automatically and gets update.
But we want to where you got stuck and what's your exact requirement.
12-26-2012 02:46 AM
I am using a ListField Control to display data returned from xml webservice. I want to refresh the ListField or the screen every minute to update the ListField with new records or data. I tried using the code below but it is not working properly (It is hanging).
--------------------------------------------------
public MyApp()
{
// Push a screen onto the UI stack for rendering.
// Push a screen onto the UI stack for rendering.
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new MyScreen());
}
},5000,true);
}
12-27-2012 07:32 PM
There are a number of options:
But possibly the easiest way to do this is to create a new ListField each time, then in an invokeLater block, delete the old one and replace with the updated one. Give this a try and see how you get on with it.
12-28-2012 12:29 AM
I have tried that but it not working the way i want it. I wan it to refresh and update like the BB messenger does.
12-28-2012 12:55 AM
But after refresh or on refresh it sets focus to the first row in the ListField. I don't want that. I want it to maintain its current focus after refresh so that a user wont even know that there was a refresh.
protected void onUiEngineAttached(boolean attached) {
if (attached) {
// TODO: you might want to show some sort of animated
// progress UI here, so the user knows you are fetching data
Timer timer = new Timer();
// schedule the web service task to run every minute
timer.schedule(new WebServiceTask(), 0, 60*1000);
}
}
public MyScreen() {
setTitle("yQAforum");
listUsers.setEmptyString("No Users found", 0);
listUsers.setCallback(this);
add(listUsers);
}
private class WebServiceTask extends TimerTask {
public void run() {
//Fetch the xml from the web service
String wsReturnString = GlobalV.Fetch_Webservice("myDs");
//Parse returned xml
SAXParserImpl saxparser = new SAXParserImpl();
ByteArrayInputStream stream = new ByteArrayInputStream(wsReturnString.getBytes());
try {
saxparser.parse( stream, handler );
}
catch ( Exception e ) {
response.setText( "Unable to parse response.");
}
// now, update the UI back on the UI thread:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
//Return vector sze from the handler class
listUsers.setSize(handler.getItem().size());
// Note: if you don't see the list content update, you might need to call
// listUsers.invalidate();
// here to force a refresh. I can't remember if calling setSize() is enough.
}
});
}
}
12-28-2012 07:13 AM
If I understand this correctly, you are telling us that creating a new ListField and replacing the old one as suggested does correctly update the screen, but the problem with is approach is that it resets the user position in the ListField.
Can you describe the contents of the update. Does it only contain extra rows? Or does it remove rows as well? Can the contents of rows change?
Say the user was focused on row 20, there were 50 rows in total on the list the user was currently displaying and the screen was displaying rows 10 to 19.
When an update happens, rows 1 to 50 would always remain the same and the update could add rows to the list. In this case, you can just leave the user displaying the same row as they were.
Alternatively, the update could send down 55 rows, but they are in fact the old rows 5 to 50, with an additional 10 rows. So in the new list, the user would have to be focused on row 15 as that is the same row as was row 20 in the old list.
The easiest way to approach this does depend on what the update contains.
12-29-2012 12:34 PM
P,
The paragraph below best describe how it should work.
When an update happens, rows 1 to 50 would always remain the same and the update could add rows to the list. In this case, you can just leave the user displaying the same row as they were.
Thank you
12-29-2012 07:02 PM
Given this description the best option seems to try to just add rows to whatever collection you use and then just set the size to reflect the new size. I've never done this but I suspect it should work.
So in your XML processing should add to the collection your ListField is using. Then in your call back your get()..) you will return the appropriate entry from the collection and your drawListRow will draw the appropriate entry.
Give this a try, let us know how you get on.
If you are struggling to get this going, then create a simpler test sample code where you have a menu item that adds rows to a ListField. Tthen if you can't get this simpler case going, you can post the code here and we can help. Don't post your current code as it will too complicated and involved for us to be able to try for ourselves.
I do have one comment though. i don't think a TimerTask is a good thing to use when doing long processing like network processing. i think that you can use the TimerTask to start a background Thread.
And remember that background Threads can't directly update the UI. Do the setSize from the UI Thread.
12-30-2012 04:31 AM - edited 12-30-2012 04:32 AM
P, I am a newbie in java. Can you please provide me with a code snipet that uses a List Field to display data returned in a web service xml using either DOM or SAX parser. This List Field should be refreshed at a specified time interval without the user being aware. This is to show newly added data. Thank you