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: 38
Registered: ‎02-04-2009
My Device: 9530
Accepted Solution

onFocusNotify and ObjectChoiceField together

[ Edited ]

hey guys,

 

So I have this MainScreen that constructs the window. Inside the window I have some ObjectChoiceFields. They work perfectly when I don't have the onFocusNotify method in the MainScreen. When I add it in though, the ObjectChoiceField will keep selecting itself. What I mean by this is: When you click on it and it drops down, then you make a selection, it will treat your selection as if you selected and immediately pressed the drop down again. Its kind of a simple error, but it can be annoying for the users to have to deselect the box everytime.

 

I've tried constructing the ObjectChoiceFields in multiple ways. Here are two ways I tried to do it but they don't work:

 

 

Case 1

public class StatusWindow extends MainScreen implements FieldChangeListener
{

public StatusWindow(LoginSaver l, boolean b)
{

//...lots of code

final StatusWindow self = this;

wherechoices = new ObjectChoiceField("Where ", wherelist, 0, Field.FIELD_LEFT)

{
            protected void fieldChangeNotify(int context)
            {
                System.out.println("where pressed");
                if (getSelectedIndex() > 0)
                {
                    where.setText(((String)(getChoice(getSelectedIndex()))));
                    self.updateLabels();
                }
                setSelectedIndex(0);
            }
 };

 //more stuff

}

 

protected void onFocusNotify(boolean focus)
{
        if (focus)
        {
            System.out.println("Regained focus, but recently refreshed already");
        }
        else
        {
            System.out.println("Lost focus");
        }
 }

 

}

 

Case 2

 

public class StatusWindow extends MainScreen implements FieldChangeListener
{

public StatusWindow(LoginSaver l, boolean b)
{

//...lots of code

final StatusWindow self = this;

whateverchoices= new ObjectChoiceField("Whatever", whateverlist, 0, Field.FIELD_LEFT);

whateverchoices.setFocusListener(this);

//....

}

 

public void fieldChanged( Field field, int context )
{

if (field.equals(whateverchoices)

{
                if (whateverchoices.getSelectedIndex() > 0)
                {
                    whatever.setText(((String)(whateverchoices.getChoice(whateverchoices.getSelectedIndex()))));
                    updateLabels();
                }
                whateverchoices.setSelectedIndex(0);
               

}

}

 

protected void onFocusNotify(boolean focus)
{
        if (focus)
        {
            System.out.println("Regained focus, but recently refreshed already");
        }
        else
        {
            System.out.println("Lost focus");
        }
 }

 

}

 

I've tried overwriting the onFocusNotify for the ObjectChoiceField but that didn't work. I tried focusRemove(), setVisualState(int visual) with no avail.

Any one know a solution or at least a hack to have it not automatically reselect the ObjectChoiceField again? thanks guys.

Message Edited by azdragon2 on 07-14-2009 04:04 AM
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: onFocusNotify and ObjectChoiceField together

What BlackBerry Smartphone model and BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.  What happens if you call super.onFocusNotify within your onFocusNotify method?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 38
Registered: ‎02-04-2009
My Device: 9530

Re: onFocusNotify and ObjectChoiceField together

[ Edited ]

Sorry for taking me so long to respond

 

I've tested it on the 8320:

v4.5.0.55

 

the 8830:

v4.2.2.123

 

the 8900

v4.6.1.94

 

they all treat it the same

Message Edited by azdragon2 on 07-17-2009 07:06 AM
Developer
Posts: 38
Registered: ‎02-04-2009
My Device: 9530

Re: onFocusNotify and ObjectChoiceField together

[ Edited ]

It appears to be thinking its been clicked twice when it has only been clicked once. I've tried setting the focus to a different field after an option has already been chosen, but what happens is the ObjectChoiceField already has the second invisible "click" queue'd up. 

 

I'm thinking a possible overload of the keydown method might fix it. I'll attempt to do it this way, and report any findings/results.

 

UPDATE:

I tried overloading the keydown and keyrepeat methods for the individual ObjectChoiceField, but they aren't called when you click on an ObjectChoiceField...But I do notice that this pattern occurs when I make a selection in the objectchoicefield:

 

Calling onFocusNotify
Calling fieldChanged for wherechoices
Calling fieldChanged for wherechoices
Calling onFocusNotify

 

 

Message Edited by azdragon2 on 07-17-2009 07:30 AM
Highlighted
Developer
Posts: 38
Registered: ‎02-04-2009
My Device: 9530

Re: onFocusNotify and ObjectChoiceField together

[ Edited ]

wow,  i hate myself...I knew I did something wrong.

Like you said before MSohm, this problem happened because I was overloading the onFocusNotify and apparently this method originally does some kind of key repeat checking or something. 

 

 Solution:

Just add super.onFocusNotify(focus); at the bottom of the your overloaded onFocusNotify. This ensures everything is properly called.

 

thanks for your help MSohm,  I appreciate it man.

Message Edited by azdragon2 on 07-17-2009 07:37 AM