How do CONSUME_CLICK on a LabelField?

Hello

I listed suruneliste of names I used LabelField to display names. Now, I want to open a popup when the user clicks the labelfield. I can't find CONSUME_CLICK to use for LabelField. How to achieve it. ? I've already implemented navigationClick.

The code so far I coded is:

    public static LabelField getClickableLabelField(String label) {
        LabelField lb = new LabelField(label, Field.FOCUSABLE | Field.FIELD_LEFT | Field.FIELD_VCENTER ) {
            public void paint(Graphics g){ g.setColor(Color.WHITE); super.paint(g); }
            protected boolean navigationclick(int status, int time) {
                fieldChangeNotify(1);
                return true;
            }
        };
        return lb;
    }

IN THE IMEPLEMENTING CLASS :

            LabelField lf = Common.getClickableLabelField(nm);
            lf.setCookie(new Integer(i));
            lf.setChangeListener(this);

            public void fieldChanged(Field field, int context) {
               if (field instanceof LabelField) {
                  LabelField lf = (LabelField) field;
                  // Wanted to check if this is the correct field or not
                  if (lf.isFocus())
                     System.out.println("YES HAS FOCUS, CORRECT ONE !!! Text = " + lf.getText());
              }
              return;
            }

Can anyone help me know how to get the clicked labelfield and fieldNotify is called, and therefore the implementation class fieldChanged().

Any help is very appreciated.

Thank you

Override navigationUnclick() to always return true.

Tags: BlackBerry Developers

Similar Questions

  • How to change TextColor of LabelField

    Hello

    I want to change the color of the text of the LabelField

    I tried following code.

    _labelField = new LabelField ("Email") {}
    {} public void paint (Graphics graphics)
                   
    graphics.setColor (Color.WHITE);
    Graphics.Clear;
    Super.Paint (Graphics);
    }
    };

    but it shows me a white box instead of LabelField
    I don't want to change the background color

    Is it possible without using CustomLabelField?

    Hello

    Thanks for the Suggestion

    But I myself found the solution by playing

    with the paintground method and paint as suggested by you (Simon_hain)

    Here is my solution

    _emailLabel = new LabelField ("Email", LabelField.USE_ALL_WIDTH |) LabelField.NON_FOCUSABLE) {}
    {} public void paintBackground (Graphics g)
    g.setBackgroundColor (Color.WHITE);
    g.setGlobalAlpha (0);
    g.Clear ();
    Super.Paint (g);
    }
    {} public void paint (Graphics g)
    g.setColor (Color.WHITE);
    g.setGlobalAlpha (255);
    Super.Paint (g);
    }
    };

    Thanks for the suggestion

  • BlackBerry 6.0 API. How to make a wider LabelField (to stop the implementation of the new lines)?


    Sorry for any delay.

    Thanks for your replies.

    The problem was caused by another reason: the units of measurement that I used to set the size. The process of calculation of these sizes were some mistakes and I thought that the problem was with LabelFields (he wasn't).

    The problem is resolved.

  • Set the style and font color LabelField

    How can I set the labelField as "BOLD" and blue fonts?

    For fonts - use Field.setFont

    For color - use the following override of the paint:

    protected void paint(Graphics g) {
      int prevColor = g.getColor();
      g.setColor(Color.BLUE);
      super.paint(g);
      g.setColor(prevColor);
    }
    
  • Focus button HorizontalFieldManager on Storm problem

    I have data exploited these forums looking for a solution but found nothing.  The application I've created has a title bar with 3 fields - previous button, label, next button.  Very simple and the layout works very well.  You cannot set the focus to the right button in the simulator of storm.  You can use the keyboard to navigate to it and click back.  But the keys do not work on this button.  If I change the center field to be a button, it works for the Center button.  Never for the right button.  I think it's a bug, but if you know a whole work please let me know.  Here is the code:

             // create previous button, current label, next button        ButtonField prev = new ButtonField("Prev", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK);        _label = new LabelField("My Label", Field.FIELD_HCENTER);        ButtonField next = new ButtonField("Next", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK);
    
    HorizontalFieldManager header = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH)//HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.NO_HORIZONTAL_SCROLL)//HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.HORIZONTAL_SCROLL | HorizontalFieldManager.HORIZONTAL_SCROLLBAR | HorizontalFieldManager.RIGHTWARD)// | HorizontalFieldManager.NO_HORIZONTAL_SCROLL)
            {
                 public int getPreferredWidth()
                 {
                       return Display.getWidth();
                 }
                 protected void sublayout( int width, int height )
                 {
                    super.sublayout( width, height );
                    width = getWidth();
                    height = getHeight();               
    
                    Field leftField = getField(0);
                    if (leftField != null && equals(leftField.getManager()))
                    {
                        setPositionChild( leftField, 0, 0);
                    }
    
                    Field centerField = getField(1);
                    if (centerField != null && equals(centerField.getManager()))
                    {
                        int w = (width - centerField.getWidth()) / 2;
                        int h = (height - centerField.getHeight()) / 2;
                        setPositionChild( centerField, w, h);
                    }
    
                    Field rightField = getField(2);
                    if (rightField != null && equals(rightField.getManager()))
                    {
                        setPositionChild( rightField, width - rightField.getWidth(), 0);
                    }
                }
            };
            header.add(prev);
            header.add(_label);
            header.add(next);
            setTitle(header);
    

    Solved!

    Basically my manager should not call super, must call layoutChild before positioning and then affecting the scope of the Manager.  Yes, a lot of questions and unfortunately a lot of code examples on this site that.  Please visit this page on the managers how custom must be written:

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

  • New error screen

    Hi, I have the following code

    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.BitmapField;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.ui.*;
    public class AppLogoMainscreen extends MainScreen {
        public AppLogoMainscreen() {
                Bitmap logoBitmap = Bitmap.getBitmapResource("App_Logo.png");
                BitmapField bmf = new BitmapField(logoBitmap, BitmapField.FOCUSABLE)
                {
                    protected boolean navigationClick(int status, int time)
                    {
                        createAndDisplayMainMenu();
                        close();
                        return true;
                    }
                };
                add(bmf);
        }
        public void createAndDisplayMainMenu() {
            MainScreen newScreen = new MainScreen(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
            VerticalFieldManager backgroundManager = new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.USE_ALL_HEIGHT)
            {
                Bitmap logoBitmap2 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap1 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap2 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap3 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap4 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap5 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap6 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap7 = Bitmap.getBitmapResource("football.jpg");
                Bitmap shirtBitmap8 = Bitmap.getBitmapResource("football.jpg");
                int imgWidth = logoBitmap2.getWidth();
                int imgHeight = logoBitmap2.getHeight();
                int imgWidth1 = shirtBitmap1.getWidth();
                int imgHeight1 = shirtBitmap1.getHeight();
                int imgXPos = 5;
                int imgYPos = 15;
                int imgTop = 0, imgLeft = 0;
                public void paint(Graphics graphics)
                {
                    graphics.setBackgroundColor(Color.PALEGREEN);
                    graphics.clear();
                    graphics.setColor(Color.FORESTGREEN);
                    graphics.fillRect(0, 0, 480, 80);
                    graphics.fillRect(0,0, 20, 360);
                    graphics.fillRect(460, 0, 20, 360);
                    graphics.fillRect(0, 340, 480, 20);
                    graphics.drawBitmap(imgXPos, imgYPos, imgWidth, imgHeight, logoBitmap2, imgLeft, imgTop);
                    imgXPos = 425;
                    graphics.drawBitmap(imgXPos, imgYPos, imgWidth, imgHeight, logoBitmap2, imgLeft, imgTop);
                    graphics.drawBitmap(45, 95, imgWidth1, imgHeight1, shirtBitmap1, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap2.getWidth();
                    imgHeight1 = shirtBitmap2.getHeight();
                    graphics.drawBitmap(45, 156, imgWidth1, imgHeight1, shirtBitmap2, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap3.getWidth();
                    imgHeight1 = shirtBitmap3.getHeight();
                    graphics.drawBitmap(45, 217, imgWidth1, imgHeight1, shirtBitmap4, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap4.getWidth();
                    imgHeight1 = shirtBitmap4.getHeight();
                    graphics.drawBitmap(45, 278, imgWidth1, imgHeight1, shirtBitmap3, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap5.getWidth();
                    imgHeight1 = shirtBitmap5.getHeight();
                    graphics.drawBitmap(365, 95, imgWidth1, imgHeight1, shirtBitmap7, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap6.getWidth();
                    imgHeight1 = shirtBitmap6.getHeight();
                    graphics.drawBitmap(365, 156, imgWidth1, imgHeight1, shirtBitmap5, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap7.getWidth();
                    imgHeight1 = shirtBitmap7.getHeight();
                    graphics.drawBitmap(365, 217, imgWidth1, imgHeight1, shirtBitmap6, imgLeft, imgTop);
                    imgWidth1 = shirtBitmap8.getWidth();
                    imgHeight1 = shirtBitmap8.getHeight();
                    graphics.drawBitmap(365, 278, imgWidth1, imgHeight1, shirtBitmap8, imgLeft, imgTop);
                    super.paint(graphics);
                }
            };
            ButtonField premierButton;
            ButtonField champButton;
            ButtonField div1Button;
            ButtonField div2Button;
            ButtonField confButton;
            premierButton = new ButtonField("Premiership", Field.FIELD_HCENTER){
                protected boolean navigationClick(int status, int time)
                {
                    createAndDisplayPremiership();
                    getScreen().close();
                    return true;
                }
            };
            champButton = new ButtonField("Championship", ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);
            div1Button = new ButtonField("League 1", ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);
            div2Button = new ButtonField("League 2", ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);
            confButton = new ButtonField("Conference", ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);
            LabelField labelField = new LabelField();
            backgroundManager.add(labelField =  new LabelField("Football Ground App", Field.FIELD_HCENTER)
            {
                protected void paint(Graphics g) {
                    int prevColor = g.getColor();
                    prevColor = (Color.RED);
                    g.setColor(Color.WHITE);
                    super.paint(g);
                    g.setColor(prevColor);
                    }
            });
            Font myFont = Font.getDefault().derive(Font.BOLD | Font.ITALIC, 11, Ui.UNITS_pt);
            labelField.setFont(myFont);
            backgroundManager.add(labelField = new LabelField("For BlackBerry", Field.FIELD_HCENTER)
            {
                protected void paint(Graphics g) {
                    int prevColor = g.getColor();
                    g.setColor(Color.WHITE);
                    super.paint(g);
                    g.setColor(prevColor);
                }
            });
            labelField.setFont(myFont);
            premierButton.setMargin(10,20,3,20);
            backgroundManager.add(premierButton);
            champButton.setMargin(3,20,2,20);
            backgroundManager.add(champButton);
            div1Button.setMargin(3,20,2,20);
            backgroundManager.add(div1Button);
            div2Button.setMargin(3,20,2,20);
            backgroundManager.add(div2Button);
            confButton.setMargin(3,20,2,20);
            backgroundManager.add(confButton);
            newScreen.add(backgroundManager);
            UiApplication.getUiApplication().pushScreen(newScreen);
        }
        public void createAndDisplayPremiership(){
            MainScreen newScreen1 = new MainScreen(Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR);
            LabelField labelField = new LabelField("For BlackBerry", Field.FIELD_HCENTER);
            newScreen1.add(labelField);
            UiApplication.getUiApplication().pushScreen(newScreen1);
        }
    }
    

    Hello

    Check this code.

    Please mark as resolved messages if you found a solution.
    Feel free to press the Bravo thank the user who has helped you

  • Doubts in the Orientation of the screen

    Hi guys, I'm developing my component. In it, I add the LabelField which displays the width of the screen, and when I change the orientation, the LabelField does not replace the old width of the labelfield, but may make changes to the things that are done in the paint while screen orientation.

    How to change.

    It's code

    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    import net.rim.device.api.ui.component.LabelField;
    
    /**
     *
     * @author rakesh_2
     */
    public class Component extends Manager
    {
        LabelField ld;
        int val;
        String s,s1;
        Font ft,temp;
        Component()
        {
            super(Manager.FOCUSABLE);
            chk();
            ld=new LabelField(s);
    
            this.add(ld);
    
        }
    
        protected void sublayout(int arg0, int arg1)
        {
            chk();
    
            Field ff=this.getField(0);
            this.setPositionChild(ff, 5, 5);
            this.layoutChild(ff,Display.getWidth(), Display.getHeight()/2);
            this.setExtent(Display.getWidth(), Display.getHeight()/2);
    
        }
        public void chk()
        {
            val=Display.getWidth();
    
            s=String.valueOf(val);
            s1=s;
        }
        public void paint(Graphics g)
        {
            g.drawText(s, 15, 15);
            super.paint(g);
        }
        public void paintBackground(Graphics g)
        {
            g.setBackgroundColor(Color.LEMONCHIFFON);
            g.clear();
        }   
    
    }
    

    So how do you change the LabelField width on the orientation of the screen?

    Concerning

    Rakesh Shankar.P

    The values returned by Display.getWidth and Display.getHeight need to change after the rotation of the screen.  Screen rotation may or may not change the size of a field.  For example a field cannot take the width of the screen in portrait or landscape mode, so you won't see any changes.

  • RealTimeClockListener

    Hi all

    I'm developing an application with features of planning, and I fight with the listener of real time clock. I searched some forums and read some past expereinces but not able to put a picture of how things work. You will appreciate if someone can throw me some tips.

    My understanding is that RealTimeClockListener can be used only at the application level. Just implement a screen or a field level does not work. I tried implementing the interface at the level of the screen and it does not work. This makes sense to the OS can only notify the application about events/clock. (Please, correct me if I'm wrong)

    Assuming that the above statement is correct: I'm trying to implement a clock for one of the embeded LabelFiels in one of the present VerticalFieldManagers on the screen of my mail.

    How can I make the LabelField know that an event notification arrived at the application level? Or others, how to get the application published the event of clock on its screens?

    AH HA! I can answer to this

    I have developed an application that i needed the same thing... I just needed a clock to display

    anyway... first of all, on the main thread you you must implement the RealtimeClockListener interface (assuming that you are dealing with just the main thread for the moment) on the class... and then you need add the listener to the thread by this.addRealtimeClockListener (this); call

    Then, you need to add the methods implemented (only public Sub clockUpdated())

    now to briefly explain RealtimeClockListener... the system (core blackberry) called clockUpdated() every minute... every application which can be a listener will run their code for clockUpdated() when it is called by the system

    Ok! That's the listeners!

    now a little 411 on the fields... When the fields are added to the screen... everything said is the screen is now reference the field. the field is editable in fact after the fact, it was added to the screen... That said... to pass a labelfield text is simply field.setText (String text);

    but for this appeal, it must be static... which is OK because it must be static to be referenced by other classes (such as the main thread class!) ... Note: be aware that we use static variables, there is only so by class and by thread! to make more, use a static vector (which you will only need 1) you can add a list of several labelfields

    Now let's skip to our main class!

    in the clockUpdated() function, all you have to add is screenclass.field.setText (String text); in there, and each time the clock update, the clockUpdated() function will be called, which will change your labelfield! awesome huh? I think so.

    hope that helps!

  • Add the label as href field

    Hello

    Can I have a label as a href field?

    I want to just display the clickable text that opens a url on the blackberry browser.

    Thank you

    I recommend looking in the forum before posting a question.  This question was asked several times before.

    This is such a thread:

    http://supportforums.BlackBerry.com/T5/Java-development/how-can-i-make-a-labelField-clickable/m-p/58...

  • Page layouts

    Hi all

    How can I add a LabelField at the top of the screen and a ButtonField at the bottom of the screen. ? I use a Horizontal and Vertical Field Manager, but it does not work...   I need a space between LabedField and ButtonField...

    Thanks in advance...

    Hello

    I used my oun spacer and work...

    Thank you...

  • Use a BitmapField to multiple screens...

    How can I add a LabelField in multiple screen.

    his gift of illigalexception.

    even I want to dynamically set images on a BitmapField() in a static way.

    But his rising illigalexception in both cases.

    You cannot add a field twice. is there a reason why you would want?
    If you divide your level of data and user interface, you can load bitmaps into your class of data once and reuse it for each bitmapfield you create.
    or you can pass multiple screens using several officials, with a fixed part of the screen remains the same.

  • How to make a LabelField align right when the text is long?

    In order to make a good LabelField aligned, I create the LabelField with style "FIELD_RIGHT and add it to a value for money, it works when the text can be displayed on a single line." But when the text is long, over a single line, it works well.

    For example, if the text is "ABDEL FARZAD", appears like this:

    It looks like aligned left

    How can I get it?

    .

    No guarantee, but instead of Field.RIGHT, try

    FIELD. USE_ALL_WIDTH | DrawStyle.RIGHT

  • How to show the number n of labelfields in a HFM without roller horizontal sc

    Hi all

    I want to show n number of labels without scrolling in a HFM areas, how?

    The suggestion above reduces to a minimum the width given to each LabelField so that they fit.  If you want just the overlow when the screen width has been reached, try FlowFieldManager.

  • How to select and change the LabelFields / ButtonFields table 2D

    Hi everyone, I'm new here and I'm new to the blackberry development.

    For a project student I'm working, I have a table 2D-ButtonFields, (I can change LabelFields if it's easier) which I use to create a Sudoku grid.

    I understand that this is really basic but I want the user to simply scroll the table 2D to a particular cell, and be able to type in a number on the keyboard instantly change the label of the ButtonField or LabelField, IE their assumption of Sudoku.

    I have really problems that I'm not familiar with how blackberry accepts user input and how it can be used with the setText method.

    So, essentially, I would like some sort of way to determine the currently selected cell (without is activated) and then for this selected cell so that the setText() method applied

    Can someone help me? I can post a code if it helps but I'm not sure it will as you al will understand how basic it is.

    Thank you in advance and I hope I can return the favor as soon as

    You can use a focuschangelistener to be aware of policy changes. or call the getLeafFieldWithFocus() to retrieve the current field.

    You can't make buttonfields editable, but you can read user input and treat it.

    for sudoku you need only numbers, you can use the keyChar method to read the characters.

    Check if your target field is one of your buttons. Check to see if the tank is entered or Louis tank (Keypad.getAltedChar) is a number (Characters.isDigit).

    You can call setText on of the buttonfield.

  • How to create a labelfield with fixed width and dynamic height?

    I got this question in fact for a long time and I have not found answer in this forum so far.

    As we know, we can use:

    public int getPreferredWidth()
    {
        return fixedSize;
    }
    
    protected void layout(int width,int height)
    {
        super.layout(getPreferredWidth(), getPreferredHeight());
        super.setExtent(getPreferredWidth(), getPreferredHeight());
    }
    

    to set the width fixed in a field, but if the text is too long and should be multiline, this will bring problem, getPreferredHeight() only returns the preferred height, which is actually not the actual height, so the text will be hashed.

    So what should this setting? height?

    super.setExtent(getPreferredWidth(), height));
    

    No.... the height value is too large.

    So, how can we set this parameter to make this labelfield looks perfectly.

    Any idea?

    A search on the web is expected to increase a lot of examples of functions in Java text wrapping. Especially for BlackBerry, you can use Font.getAdvance (String text, int start, int len) to measure the width of a text segment without the expense of creation of substrings.

    The basic logic is to analyze the text character by character. If the "\n" character, force a line break. If the character is a space, then it is a line break candidate; Check if the line so far is set. If so, then move the candidate to that character end and continue; If this is not the case, go back to the previous candidate break and put an end to the line right there. The loop is initialized so that there is always at least one character on the line. The process ends when you run out of text. Details (including dealing with empty text, several spaces, etc.) are kept as an exercise for the reader, or search the Web well.

    I wouldn't worry efficiency. Put on the page of the field is not all that often, and when it's done, there's no escape from the need to make the work of packaging line at some point before the text is rendered on the screen. One way to avoid unnecessarily repeating work is to memoize the function of packaging line: wrapped lines and the width of the film cache and reuse them as needed. The cache is marked invalid if changes to text or the current width and the width of the film cached differ.

Maybe you are looking for

  • When I close the tab it does not return the last active tab

    My English is not very good, so I'm sorry about that. I want to return last active tab when I close a tab.Example; I use 2. tab, then I spend 4. tab, then close it. Firefox goes to 5. tab, not 2. I did a google search, but I can't find anything usefu

  • contacts sucked out of my mac. How to remove only the?

    I just put Skype on my mac and it auto added my entire contacts in my address book. I don't want these CONTACTS, but can't say which ones I had before. How can I distinguish and cancel this? It's a horror for me to have thousands of addresses of Skyp

  • Pavilion P7-1414: Cable 11 disconnected my p7-1414, where does go?

    Hello, my problem, as indicated in the title, is a wire labeled "Cable 11" disconnected from inside my PC I installed an SSD, the other day. I just need to know where he'll be back because I can not find it. The wire comes out of the front (but still

  • Maximum memory for Portege Z930 - 14L

    Hello I have a Portege Z930 - 14L with 8 GB memory and wonder what is the maximum memory I can add? I saw the following in the description, but I don't understand if this means that the maximum is 12 GB (4 GB onboard + 8 GB expansion) or 16 GB (2x8GB

  • On DV7 Vista system restore

    Hi, my C: drive becomes unreliable, so I need to restore my system to a record nine without a system image. I have Recovery Manager restore disks (3), but these are not bootable. How to proceed? -is it possible to run the unreliable disk and build th