BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-20-2007, 04:29 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2007
Model: 8100
Carrier: T-Mobile
Posts: 54
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Focus problem! I'm going out of my mind!!!

Please Login to Remove!

Hi all,

This is a *seemingly* simple example of something I should be able to do.
I have a HorizontalFieldManager that contains a focusable, NullField so that I can utilize the onFocus() and onUnfocus() methods of the HorizontalFieldManager.
When you cursor into the HorizontalFieldManager, the onFocus() method adds two ButtonFields to itself, then sets its focus to the first ButtonField.
The focus IS on the first button, however, the button isn't "lit up" with the blue color that buttons normally are. If I move the focus to the 2nd button, then back to the 1st button, the button gets the correct decoration.
Any ideas anyone ????

Code Follows

Much appreciated

Matthew Wheaton


Code:
package com.wcs.blackberry;

import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class Sandbox extends UiApplication
{
  public static void main(String[] args)
  {
    Sandbox theApp = new Sandbox();
    theApp.enterEventDispatcher();
  }

  public Sandbox()
  {
    MainScreen screen = new SandboxScreen();
    pushScreen(screen);
  }
}

final class MyVFM extends HorizontalFieldManager
{
  protected void subpaint(Graphics g)
  {
    g.setBackgroundColor(Color.LIGHTGREY);
    g.clear();
    super.subpaint(g);
  }

  protected void sublayout(int maxWidth, int maxHeight)
  {
    int width = 200;
    super.sublayout(width, maxHeight);
    setExtent(width, getExtent().height);
  }

  public int getPreferredWidth()
  {
    return 200;
  }

  protected void onFocus(int aDirection)
  {
    super.onFocus(aDirection);
    ButtonField bf = new ButtonField("Button One");    
    add(bf);
    ButtonField bf1 = new ButtonField("Button Two");    
    add(bf1);
    setFieldWithFocus(bf);
  }

  protected void onUnfocus()
  {
    super.onUnfocus();
    delete(getField(getFieldCount()-1));
  }  
}

final class SandboxScreen extends MainScreen
{
  public SandboxScreen()
  {
    super(MainScreen.DEFAULT_MENU | MainScreen.DEFAULT_CLOSE);

    MyVFM vfm = new MyVFM();
    vfm.add(new LabelField("ABC"));
    vfm.add(new NullField(Field.FOCUSABLE));

    add(new EditField("", "Field One", 50, Field.EDITABLE));
    add(vfm);
    add(new EditField("", "Field Two", 50, Field.EDITABLE));
  }

  public boolean onClose()
  {
    System.exit(0);
    return true;
  }

  public boolean keyChar(char key, int status, int time)
  {
    invalidate();
    switch (key)
    {
      case Characters.ESCAPE:
        onClose();
        return true;
    }
    return super.keyChar(key, status, time);
  }

}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.