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
New Contributor
Vish3104
Posts: 3
Registered: ‎05-14-2012
My Device: Bold 9700

HorizontalFieldManager and Dialog not working together.

hi.. i'm new in blackberry development. i want to show a diaolg when i enter a new screen(extending mainScreen). the screen contains hotizontal field manager and i've set it as Banner using setBanner(hortzfieldManager); Its throwing an exception as pushModalScreen called by non-event thread.   Any help would be appreciated..

Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: HorizontalFieldManager and Dialog not working together.

 

Hi @Vish3104

 

The error that you mention indicates you are trying to change the UI from a thread which is not the event-thread.

 

Did you call the enterEventDispatcher() function in your main function?

 

I suggest you go over on the "hello world" example and try adding a dialog screen to screen in the example.

 

Hope that helps,

 

E.

Please use plain text.
New Contributor
Vish3104
Posts: 3
Registered: ‎05-14-2012
My Device: Bold 9700

Re: HorizontalFieldManager and Dialog not working together.

i've written tha dialog code and horizontalFieldmanager both in the constructor of myScreen class...

 

 

Please use plain text.
Contributor
hrushikeshsalkade
Posts: 17
Registered: ‎12-20-2011
My Device: Bold 9780

Re: HorizontalFieldManager and Dialog not working together.

Hi Vish,

Can you post your code here ? So that we can trace your error.

Please use plain text.
New Contributor
Vish3104
Posts: 3
Registered: ‎05-14-2012
My Device: Bold 9700

Re: HorizontalFieldManager and Dialog not working together.

public class MyScreen extends MainScreen implements FieldChangeListener
{

private LabelField result;
private BitmapField btnrefresh,btnhelp;
HorizontalFieldManager hfm1;
Background bgr;
private Bitmap startBitmap;


LabelField time;
long mille = 0;
Timer timer = null;
TimerTask task = null;

 

CustomVerticalManager mManager = new CustomVerticalManager();

public MyScreen ()
{
startBitmap = Bitmap.getBitmapResource("img/start.png");
btnrefresh = new TouchBitmapField(startBitmap);

startBitmap = Bitmap.getBitmapResource("img/start.png");
btnhelp = new TouchBitmapField(startBitmap);

hfm1 = new HorizontalFieldManager();

btnrefresh.setChangeListener(this);
btnhelp.setChangeListener(this);

btnhelp.setMargin(0, 0, 0, 385);

hfm1.add(btnrefresh);
hfm1.add(btnhelp);
hfm1.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));

startBitmap = Bitmap.getBitmapResource("img/bg1.png");
bgr = BackgroundFactory.createBitmapBackground(startBitmap,0,50,0);
getMainManager().setBackground(bgr);

 

setBanner(hfm1);

add(mManager);

 

Dialog.alert("Hello.....");

 

class CustomVerticalManager extends VerticalFieldManager implements FieldChangeListener

{

private Bitmap startBitmap;
private BitmapField touch;

 

public CustomVerticalManager()

{

startBitmap = Bitmap.getBitmapResource("img/resetbutton.jpg");
touch = new BitmapField(startBitmap);

touch.setChangeListener(this);
add(touch);
}

protected void sublayout(int width, int height) {

layoutChild(touch,500,200);

setPositionChild(touch,270,120);

setExtent(440,300);
}

public void fieldChanged(Field field, int context) {

}
}

public void fieldChanged(Field field, int context) {

}
}

Please use plain text.
Developer
simon_hain
Posts: 16,207
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: HorizontalFieldManager and Dialog not working together.

the constructor of the mainscreen runs before the application enters the event dispatcher.
wrap the dialog into an invokelater.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.