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

Native Development

Reply
Developer
Posts: 16,524
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
Accepted Solution

Clickable labelfield

Is there a way to create a clickable labelfield? Or would i have to use a listfield even when there are only two entries?

I would like a clickable label that covers the full container width, despite having a short text.

----------------------------------------------------------
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
Developer
Posts: 330
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Clickable labelfield

This worked for me.

 

import bb.cascades 1.0
 
Page {
    Container {
            id: containerID
            background: Color.Blue
            minHeight: 100.0
        Label {
            text: "Click Me"
            textStyle.fontSizeValue: 6.0
            }
            onTouch: {
                containerID.background = Color.Green;
        } 
    }
}

 

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: Clickable labelfield

Use a gesture handler

Label {
gestureHandlers: [
TapHandler{
onTapped: dowhatever
}
]
}
Like all of my posts
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Clickable labelfield

[ Edited ]

Curiously, neither Bluenoser's nor kylefowler's solutions are having any effect here. I have a nice Label inside a Container, with the Container background bright red so I can see where the touchable area ought to be (assuming the Container covers the space of all its children, as it appears to be doing). With either approach above I get no event when touching/tapping/or anything else.

 

Edit: Never mind... I had a ListView over top of the Label (both in a DockLayout) and thought I had it set visible=false but it was merely empty. It was intercepting the touch events.  Either one of the above approaches works for me now.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 16,524
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Clickable labelfield

Kyles solution works better for me, onTouch seems to be triggered 3 times for each tap, and it keeps firing if the user taps it longer.
----------------------------------------------------------
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
Developer
Posts: 887
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha

Re: Clickable labelfield


simon_hain wrote:
onTouch seems to be triggered 3 times for each tap, and it keeps firing if the user taps it longer.

 

This can be fixed by using

 

onTouch:
{
        if (event.isDown())
        {
             //code goes here
	}
}

 


Read my thoughts on BlackBerry Development at news.ebscer.com