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
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Need Help with Custom PopupScreen Buttons

This is driving me crazy...mostly because I think I almost have it..mostly because I can't find the articles I need to do this myself.

 

I'm trying to create a custom popup that displays an EditField, a large, rectangular EditFields and two buttons. 

I'm having the most problems with the buttons.

 

I basically want to create buttons that act like the Dialog button fields.  I'm not extending Dialog because I can't control the how the buttons are positioned.

 

I want the buttons to act so that I can write code like

 

int answer = customPopup.ask();

 

right now I have the following code set up

 

 

        FieldChangeListener okl = new FieldChangeListener() 
        {
            public void fieldChanged(Field field, int context) 
            {
                if((user.getText().length() & password.getText().length()) == 0)
                {
                    Dialog.alert("Please enter valid credentials");
                } else
                {
                    fieldChangeNotify(1);
                }
            }
        };

 

But I don't know how to capture the fieldChangeNotify so that  I can create a method like:

 

public int ask()

{

  return selectedValue

}

 

This was easy enough to do with a custom Dialog...but I can't quite figure out how to do it with a custom Popup.

 

Also, if anyone has any good, complete tutorials on the RIM API gui elements...especially ButtonFields and Managers, I'd appreciate links.  The docs I've seen in the knowlegebase have something like...."to create a custom Button, include the following line 'ButtonField custom = new ButtonField()'"  and that's it!  Nothing about how to make it do anything!

 

Developer
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: Need Help with Custom PopupScreen Buttons

Basically,

 

1) you need to extends PopupScreen and write your own layout for your dialog.

 

 

2) After you create your own Dialog, maybe it will hold a public static method, for example ask

 

public static int ask(String msg){

      MyDialog dialog = new MyDialog(msg);

      UiApplication.getUiApplication().pushModal(dialog)

      return dialog.getSelected();

}

 

 

somthing kind of this.

 

Cheers.

 

 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

 


Jeff_Lu wrote:

Basically,

 

1) you need to extends PopupScreen and write your own layout for your dialog.

 

 

2) After you create your own Dialog, maybe it will hold a public static method, for example ask

 

public static int ask(String msg){

      MyDialog dialog = new MyDialog(msg);

      UiApplication.getUiApplication().pushModal(dialog)

      return dialog.getSelected();

}

 

 

somthing kind of this.

 

Cheers.

 

 


 

 

I've extended the PopupScreen successfully.  I've created the buttons successfully.  The problem I'm having is how to implement the dialog.getSelected you mentioned in the code above....as there is no getSelected() method in the PopupScreen class or any of its superclasses...unless I overlooked something.

 

Also, I don't think you can instantiate an object from within the class that is creating it.

 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

Jeff is suggesting that you need to implement getSelected(), or getSelection(), or whatever.

 

You have set the result of the dialog dismissal, like 0=CANCEL or 1=SUBMIT (or whatever).

 

int selection = CANCEL, etc...

 

This value is set within a class property. The 'getter' is called after dismissal to retrieve the value.

 

public int getSelection()

{

    return selection;

}

 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

 


RexDoug wrote:

Jeff is suggesting that you need to implement getSelected(), or getSelection(), or whatever.

 

You have set the result of the dialog dismissal, like 0=CANCEL or 1=SUBMIT (or whatever).

 

int selection = CANCEL, etc...

 

This value is set within a class property. The 'getter' is called after dismissal to retrieve the value.

 

public int getSelection()

{

    return selection;

}

 


 

 

I think I understand.  When you say, "you have set the result of the dialog dismissal, like 0=CANCEL or 1=SUBMIT (or whatever)...."  you're referring to the actual use of the custom dialog, right?

 

Which means you're saying I need to set that up in my custom PopupScreen classs, right?

 

I've got temporary code in place in my custom PopupScreen class  that returns a Field, not an int...but is this what you're talking about?

 

 

 public Field ask()
    {
        UiApplication.getUiApplication().pushModalScreen(this);
        Field f = hfm.getFieldWithFocus();
        return f;
    }

 

I'm using it until I've solved a couple other, larger code problems (some flow problems and how to create a custom popup with two one-line EditFields and a larger custom EditField)

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

[ Edited ]

I'm not sure this code will do what you want:

 

 public Field ask()
    {
        UiApplication.getUiApplication().pushModalScreen(this);
        Field f = hfm.getFieldWithFocus();
        return f;
    }

 

Remember that the modal push will not return until the Screen has been popped of the stack.  I would be very interested to know of a manager that is not displayed can 'have focus'.

 

That said, if you had some focus listener in this screen that set the 'inFocus' Field to a local variable, then you could return the Field that has been set.  Alternatively have a FieldChangedListener associated with the buttons and have it set a local variable.

 

Edit:  I'm wondering if you haven't quite 'got' how the BB hangs together.  I would recommend the book that I reviewed here:

http://supportforums.blackberry.com/t5/Java-Development/Beginning-BlackBerry-Development-by-Anthony-...

and there are some good Blog entries on this site:

http://www.thinkingblackberry.com/archives/category/basics

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

[ Edited ]

 


peter_strange wrote:

I'm not sure this code will do what you want:

 

 public Field ask()
    {
        UiApplication.getUiApplication().pushModalScreen(this);
        Field f = hfm.getFieldWithFocus();
        return f;
    }

 

Remember that the modal push will not return until the Screen has been popped of the stack.  I would be very interested to know of a manager that is not displayed can 'have focus'.

 

That said, if you had some focus listener in this screen that set the 'inFocus' Field to a local variable, then you could return the Field that has been set.  Alternatively have a FieldChangedListener associated with the buttons and have it set a local variable.

 



 

 

Actually this code does work for now, although it may be a bit clumsy.  This is how I use it:

 

 

            UiApplication.getUiApplication().invokeAndWait(new Runnable()
            {
                public void run()
                {
                    tcs = new tumbleCredsScreen();
                    // static Field variable
                    tumbleAuthSet.answer = tcs.ask();
                }
            });
            // if Field returned is "cancel"
            if (answer == tumbleCredsScreen.cancel)
            {
                break;
            }
            // else if Field returned is "ok"
            else if(answer == tumbleCredsScreen.ok)
            {
                // do something here
            }

 

I plan to change it to something resembling Rex_Doug's suggestion...I'm just working on some more difficult problems first (i.e. implementing a layout Manager)

 

 

 


peter_strange wrote:

 

Edit:  I'm wondering if you haven't quite 'got' how the BB hangs together.  I would recommend the book that I reviewed here:

http://supportforums.blackberry.com/t5/Java-Development/Beginning-BlackBerry-Development-by-Anthony-...

and there are some good Blog entries on this site:

http://www.thinkingblackberry.com/archives/category/basics


 

 

Heh.  You don't have to wonder...I'm positive I don't quite completely get how the bb hangs together.  I actually have the second link you posted bookmarked...their article on threading was the best one I found on the subject and I referred to it often when writing my first app.  I'm also using the two articles they wrote on developing layout Managers for this project.

 

The first link is new to me...I'll definitely check it out.  I also did a brief search for a "Blackberry Programming for Dummies" type book at the local bookstore but the only ones were on how to use a Blackberry.

 

As soon as I get the most pressing Blackberry apps written for my Bold I thought I'd go back compile all the links and info I found when starting out...especially the stuff on developing Blackberry apps in NetBeans...and post them here.  It's just that I've been frustrated about the lack of bb apps available for so long that I've got a long list of apps to write...three of which I needed yesterday.  The first one is done and I'm working on the second and third.

 

EDIT:  Here are the two articles from thinkingblackberry on layout managers that I'm working with now:

http://www.thinkingblackberry.com/archives/188

http://www.thinkingblackberry.com/archives/116

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

Regarding Layout Managers, I presume you have seen these videos:

 

How to Extend Manager

http://www.blackberry.com/DevMediaLibrary/view.do?name=HowToExtendManager

 

How to Extend the Screen

http://www.blackberry.com/DevMediaLibrary/view.do?name=HowtoExtendtheScreen

 

And this KB Article:

 

How To - Create a rich UI layout with TableLayoutManager
Article Number: DB-00783
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

 

There is also a blog about this Manager:

http://supportforums.blackberry.com/t5/BlackBerry-Developer-s-Blog/How-to-use-Table-View-layout/ba-p...

 

Hopefully you will find these useful. 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Need Help with Custom PopupScreen Buttons

[ Edited ]

 


peter_strange wrote:

Regarding Layout Managers, I presume you have seen these videos:

 

How to Extend Manager

http://www.blackberry.com/DevMediaLibrary/view.do?name=HowToExtendManager

 

How to Extend the Screen

http://www.blackberry.com/DevMediaLibrary/view.do?name=HowtoExtendtheScreen

 

And this KB Article:

 

How To - Create a rich UI layout with TableLayoutManager
Article Number: DB-00783
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

 

There is also a blog about this Manager:

http://supportforums.blackberry.com/t5/BlackBerry-Developer-s-Blog/How-to-use-Table-View-layout/ba-p...

 

Hopefully you will find these useful. 


 

 

I had not seen the videos...thanks!

I think the KB was one of the search results that I discarded because it was on a table layout format but I'll go back and take a look.  Thanks for the blog post too!

 

 

EDIT:  In looking at the video, I noticed right off that it uses a different method of building a custom screen layout than the thinkingblackberry article...the video uses three managers to get the total screen effect and the article creates one manager for the entire screen.

 

I'm trying to create a manager that will be for a post popupscreen...a bitmap icon, a title field, a variable number of one line editable fields, a multiline field and a variable number of buttons across the bottom.  I'm wondering which method for creating custom Managers would be better, but since this thread was originally about PopupScreen buttons, I'll put the layout and Manager questions I have in a new post.