05-15-2012 05:34 AM - edited 05-15-2012 05:35 AM
i am doing this to print "hello " 10 times in my textbox but it prints only one time.
plz check this
class ThreadUi extends MainScreen implements FieldChangeListener
{
public ButtonField start, stop;
public TextBoxField txtfield =null;
public String str = "";
public ThreadUi()
{
ThreadScreen();
}
public void ThreadScreen()
{
HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.FIEL
hfm.setMargin(40,0,0,0);
start = new ButtonField("Start");
start.setMargin(0,10,0,0);
stop = new ButtonField("Stop");
hfm.add(start);
hfm.add(stop);
add(hfm);
txtfield = new TextBoxField(400,400);
txtfield.setMargin(20,0,0,20);
add(txtfield);
start.setChangeListener(this);
stop.setChangeListener(this);
}
public void startThread()
{
Thread th = new Thread()
{
public void run()
{
try
{
Thread.currentThread().sleep(1000);
}
catch(InterruptedException e){}
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
for(int i = 0; i<10;i++)
{
str = "hello";
txtfield.setText(str);
}
}
});
}
};
th.start();
}
public void fieldChanged(Field field, int context)
{
if(field == start)
{
startThread();
}
else if(field == stop)
{
}
else
{
}
}
}
05-15-2012 05:37 AM
05-15-2012 05:42 AM
your means should display first
then sleep.
05-15-2012 05:45 AM
it is showing only one hello look.
05-15-2012 05:46 AM
Read carefully simon's post.
You update the same(!!!) text field with the same text so it doesn't really change...
Try adding more text fileds or changing the value of the text field to include the old text with the new text:
setText(getText() + "\n" + "hello");
05-15-2012 05:49 AM
05-15-2012 05:58 AM
i ll try to do course.
thanks
05-15-2012 06:39 AM
Thanks
mr.simon
![]()
i got the solution finally.
05-15-2012 07:00 AM