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: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

ListField repeatedly calling onFocus()

Hello,

 

For OS 6.0, does anyone know what causes a ListField's onFocus() method to repeatedly be called if you hold down your finger down on an empty area of the ListField (where there are no rows) and move your finger around?  I do not see this behavior on 5.0.  I'm not sure why onFocus() is repeatedly being called as when I do this, one of my list rows is selected and the ListField should already have focus.

 

This is affecting some logic that I am using to dynamically add MenuItems when the ListField is focused.  Therefore, I'm trying to stop that behavior...

 

Thanks!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

I would try to replicate this is a small piece of standalone code that you can post here for review. 

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

[ Edited ]

Here is the code of my ListField instantiation, which also handles the showing/hiding of menu items for selected rows:

 

ListField instantiation:

main_lf = new ListField() {

RefreshMenuItem refreshMenuItem = new RefreshMenuItem(this);
	DeleteMenuItem deleteMenuItem = new DeleteMenuItem(this);

	protected void drawFocus(Graphics graphics, boolean on) {
	}

	public boolean keyChar(char key, int status, int time) {
		if (key == Characters.ENTER) {

			String tid = (String) main_lf.getCallback().get(
					main_lf, main_lf.getSelectedIndex());

			synchronized (UiApplication.getEventLock()) {
			UiApplication.getUiApplication().pushScreen(
				new DetailScreen(MasterScreen.this, tid));
			}

		}
		return super.keyChar(key, status, time);

	}

	protected boolean navigationClick(int status, int time) {

		String tid = (String) main_lf.getCallback().get(main_lf,
			main_lf.getSelectedIndex());

		synchronized (UiApplication.getEventLock()) {
			UiApplication.getUiApplication().pushScreen(
			new DetailScreen(MasterScreen.this,tid));
		}

		return true;
	}

	protected boolean navigationMovement(int dx, int dy,
		int status, int time) {
		this.invalidate(getSelectedIndex());
		return super.navigationMovement(dx, dy, status, time);
	}

	protected void onFocus(int direction) {
		MasterScreen.this.addMenuItem(refreshMenuItem);
		MasterScreen.this.addMenuItem(deleteMenuItem);
	}

	protected void onUnfocus() {
		MasterScreen.this.removeMenuItem(refreshMenuItem);
		MasterScreen.this.removeMenuItem(deleteMenuItem);
	}

	protected void paint(Graphics graphics) {
		graphics.setColor(Color.BLACK);
		super.paint(graphics);
	}
};

 

DeleteMenuItem:

public class DeleteMenuItem extends MenuItem {

private ListField main_lf;

	public DeleteMenuItem(ListField main_lf) {
		super("Delete selected", 20, 10);

		this.main_lf = main_lf;
	}

	public void run() {

		String tid = main_lf.getCallback()
					.get(main_lf, main_lf.getSelectedIndex()).toString();

		DatabaseFunctions.deleteRecord(tid);
		createListField();

	}
}

 

RefreshMenuItem:

public class RefreshMenuItem extends MenuItem {

	private ListField main_lf;

	public RefreshgMenuItem(ListField main_lf) {
		super("Refresh selected", 20, 10);

		this.main_lf = main_lf;
	}

	public void run() {

		String tid = main_lf.getCallback()
					.get(main_lf, main_lf.getSelectedIndex()).toString();

		String number = DatabaseFunctions.getMasterRecord(tid)
					.getNumber();

		DatabaseFunctions.deleteRecord(tid);
		getNumberInformation(number);

	}
}

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

Unfortunately this is not standalone since we don't have CustomListField or DeleteMenuItem or RefreshMenuItem.  Does the problem happen if you use a standard ListField and Menu items?

 

Also I'm not sure why you don't do this

main_lf = new CustomListField() {

RefreshMenuItem refreshMenuItem = new RefreshMenuItem(this);
 DeleteMenuItem deleteMenuItem = new DeleteMenuItem(this);

...

 protected void onFocus(int direction) {
  MasterScreen.this.addMenuItem(refreshMenuItem);

  MasterScreen.this.addMenuItem(deleteMenuItem);

 }

...

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

Hi peter_strange,

 

Thanks for the suggestion.  I have incorporated that change into my code.  Also, I have updated the above code to use ListField instead of CustomListField, and this issue still occurs.  I have provided the code for the MenuItem's as well.

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

Found the problem:

 

Once I overrided touchEvent() for the ListField, then the problem ceased.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

That is interesting.  Wouldn't have thought of doing that!

 

Sorry I dropped out o circulation for bit - been on a call. 

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

Not a problem, you're help is always appreciated.

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

peter_strange,

 

While overriding touchEvent() can stop the MenuItems from continually adding to the menu, any ideas as to why it may be happening?  I'd rather not have to override the default behavior of touchEvent().

 

Thanks...

Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: ListField repeatedly calling onFocus()

Actually,

 

I changed my implementation to the one found here, which solves all of my problems Smiley Happy

 

http://supportforums.blackberry.com/t5/Java-Development/Problem-With-List-Field-Update/td-p/492501