11-21-2008 10:53 PM
I'm trying to write a sample application that has a big initialization that occurs as the app starts up and I want to display progress right away so I implemented an activate() which starts a thread that updates a RichTextField. Is this a good practice (implementing activate()) or is there a better way?
So far it works fine but I can't seem to get the display to scroll down as new text is added.
Code was written for JDE4.1.
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
/**
* Utility to dump ULJ databases to a server
*/
public final class AccessTest extends UiApplication {
//members --------------------------------------------------
private boolean _hasActivated = false;
private static RichTextField _output;
private SampleCreatorScreen _mainScreen;
private static class SampleCreatorScreen extends MainScreen
{
public SampleCreatorScreen()
{
super(
DEFAULT_MENU | DEFAULT_CLOSE
| Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR
);
setTitle( "Sample DB Creator" );
_output = new RichTextField( "working..." );
add( _output );
}
public boolean onClose()
{
Dialog.alert( "Goodbye!" );
close();
return true;
}
public void message(String msg)
{
synchronized( Application.getEventLock() ) {
_output.setText( _output.getText() + "\n" + msg );
//
// Try to set focus at bottom
//
int v = getVirtualHeight() - getHeight();
if( v > 0 ) {
setVerticalScroll( 0 );
}
}
Thread.yield();
}
}
private class AppInitThread extends Thread
{
public void run()
{
for( int i = 0; i < 20; i++ ) {
message( "hello " + i );
try {
Thread.sleep( 1000 );
} catch( Exception x ) {
}
}
}
}
//statics --------------------------------------------------
static public final void main(String[] args)
{
new AccessTest().enterEventDispatcher();
}
//constructors --------------------------------------------------
public AccessTest() {
SampleCreatorScreen screen = new SampleCreatorScreen();
_mainScreen = screen;
pushScreen(screen);
}
public void activate()
{
if( !_hasActivated ) {
AppInitThread t = new AppInitThread();
t.start();
_hasActivated = true;
}
}
public void message(String msg)
{
if( msg != null ) {
_mainScreen.message( msg );
} else {
Dialog.alert( "Error: message lost or null" );
}
}
}
11-24-2008 09:28 AM
12-02-2008 11:14 AM
The field created in this sample may provide you with what you are looking for.
Pimp My Object: Creating a TextBox Field
http://na.blackberry.com/eng/devjournals/resources
08-08-2009 12:41 AM
Hi all,
can blackberry APIs support views??? ( which are present in the APIs of iphone and Android) what is the alternative for those views in blackberry? i need to place a view over another view. how can i perform it in blackberry.
Thanks and Regards,
PraveenGoparaju