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
Highlighted
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified
Accepted Solution

SetFocus Issue with Tabbed Screen Page

[ Edited ]

Hi Blackberry Guys,

 

I am follwoing the Blackberry developers knowledge base artical How To - Create tabbed view screens 

as an inspiration for my custom tab screen.

 

I have to create tab control with unlimited tabs as following

Tab1 | Tab2 | Tab3 | >>


On focusChanged of >>, I delete Tab1 from the horizontal manager, and add Tab4 and set the current focus to Tab4.

 

But when I invoke the tab4.setFocus(); it throws NullPointerException

 

Here is the focusChanged event for reference

 

public void focusChanged(Field field, int eventType)
{
    if (eventType == FOCUS_GAINED)
    {
         for(int i=0;i<tabs.length;i++)
         {
            (field == tabs[i])
            {
                delete(tabPanel);
                tabPanel = getTabPanel(i);
                add(tabPanel);
                return;
            }
         }
         if(field == LabelNext)
         {
            tabs[nextTab] = getNextTab();
            hManager.add(tabs[nextTab]);
            tabs[lastTab].setFocus();
         }
    }
}

 

Any idea of implementing Tab Screen with dynamic tabs would be be very much appriciated

 

Many Thanks

Nitin Patel

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: SetFocus Issue with Tabbed Screen Page

Welcome to the forums!

 

Try wrapping setFocus() in invokeLater() - your focusChanged() is called inside a chain of calls surrounding a UI event.  Let it (and the whole chain) finish then issue the setFocus().

 

Grabbing an event lock will not do any good - you are already on event thread in your focusChanged method. You really need to let the framework finish its job with the previous event before initiating a new one. That's why invokeLater() seems like the right way to go.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: SetFocus Issue with Tabbed Screen Page

[ Edited ]

Thanks for your suggestion Arkadyz

 

I still can't get it right. I am using invokeLater as below

 

tabControl.MoveNext();

UiApplication.getUiApplication().invokeLater(new Runnable()
                      {
                          public void run()
                          {
                                  tabControl.TabLabels[tabControl.MaxTabIndex].setFocus();
                          }
                      });

 

I get the NullPointerException.

 

Am I doing anything wrong with invokeLater?

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: SetFocus Issue with Tabbed Screen Page

Can you debug your code and find out what line gives you the exception, then examine the variables on that line and see which one is null?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: SetFocus Issue with Tabbed Screen Page

 

The line below thows an exception.

tabControl.TabLabels[tabControl.MaxTabIndex].setFocus();

 

I watched all values in the statement and none of them is null.

As maintaning the tab with >> & << becoming really complex and too many things to consider,

I am looking to display all labels on Horizontal Panel with Manager.HORIZONTAL_SCROLL and it works fine for me.

 

But I am sure that using invokeLater() with bit of testing shold work in this senario.

 

Thanks