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: 24
Registered: ‎07-22-2009
My Device: Not Specified
Accepted Solution

Remove listfield selection on unfocus?

The listfield semms to keep the last item selected when the focus leave the listfield... is there a way to show every item as unselected when the focus leave the listfield?

 

Thanks!

Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: Remove listfield selection on unfocus?

Does my solution in your other thread works for you? Or do you need something else/more?

--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.
Developer
Posts: 24
Registered: ‎07-22-2009
My Device: Not Specified

Re: Remove listfield selection on unfocus?

[ Edited ]

Haven't seen that, thanks for your answer!

 

But i'm still not sure what to do with it ... i'm able to know if the focus is on the listfield or not but how can I remove the selection? Because even if the focus is on another field, the last item stay selected.

 

Thanks!

Message Edited by staticx99 on 08-18-2009 03:12 PM
Highlighted
Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: Remove listfield selection on unfocus?

[ Edited ]

In short what framework does when focus is moved (it not quite true but enough for this topic):

1) Setup Graphics object with default settings for non-focused field (including colors)

2) Pass graphics into the field that had focus for re-painting

3) Setup Graphics object with default settings for focused field (including colors)

4) Pass graphics into the field that recieves focus for painting of focused area

 

If you need just properly paint focus you can change your condition

if(listField.getSelectedIndex() == index)

in drawListRow method to

if(graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))

Important thing here is what happens at step 2 when control is asked to re-paint itself to clear focus. Last row is painted as focused because your condition is true for the last row when control.

My idea is simple: if you want you want to customize style for focus - do it only when focus area is being painted rather than every time control is repainted. And framework will do everything else for you.

 

 

Edit: some typos in description including significant one in description of step 3

Message Edited by SergGr on 08-20-2009 12:26 AM

--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Remove listfield selection on unfocus?

Hi,

 

When focus is not on listfield ,then set the selectedIndex to -1. May be this will help you in solving your issue.

 

Also look at this thread

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=25546&view=by_date...

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: Remove listfield selection on unfocus?

[ Edited ]
Rajat, I don't think that calling setSelectedIndex(-1) would help if list is not empty. AFAICS value is clamp to the  interval [0; size-1] by that method. As you can see from MSohm response in the thread you mentioned selected index not equal to focused row. If you need to distinguish "last row is selected and list field is focused" and "last row is selected and list field is not focused" cases you have to use some solution like peter_strange's one. If you want only to draw focused area properly, my solution should work
Message Edited by SergGr on 08-19-2009 12:23 PM

--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.
Developer
Posts: 24
Registered: ‎07-22-2009
My Device: Not Specified

Re: Remove listfield selection on unfocus?

Rajat : Like SergGr said , setting the selectedindex to -1 only pout the focus on the first row.

 

Thanks SerGr! Now it works fine and I can understand how the listfield really works!

I appreciate that you give all these explanation instead of only giving some working parts of code, wich is not that bad tho Smiley Happy 

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Remove listfield selection on unfocus?

Hi,

 

 

Thanks both for updating me on that Smiley Happy .

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish