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
geeneeus
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700

Odd Field getManager() Issue

I am trying to delete a Field from the screen when a delete event occurs in my app.

 

There are two ways to delete a particular item but they both use the same method/function.

 

When calling getManager() from directly in the Field it returns null.

 

When calling the Field.delete() method/function from a popup the getManager() method/function returns the Manager correctly.

 

Is there something something I am missing here?

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Odd Field getManager() Issue

Strange... getManager() will return null if your Field is not managed by anything at the moment.  Are you sure your Field is displayed when you call it "directly in the Field"? Can the call happen at other times?

----------------------------------------------------------
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
geeneeus
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700

Re: Odd Field getManager() Issue

[ Edited ]

It is definitely on the screen and most definitely should be attached to a Manager.

 

Basically the way it works is if a user presses the delete key while the Field is selected it will delete it (after a confirmation dialog of course) but getManager() returns null.

 

There is also a popup that gives you extra options on the field (something that looks a little similar to the Context Popups on OS6) that gives you the option to delete the Field and when you call the very same method for the Field in the popup it deletes fine.

 

No idea what the difference is and can't seem to find a solution.

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Odd Field getManager() Issue

On what level are you overriding keyChar (or wherever you catch that Delete key)?  Care to share the relevant code?

----------------------------------------------------------
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
geeneeus
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700

Re: Odd Field getManager() Issue

 

    protected boolean keyChar(char c, int status, int time) {
        switch(c) {
        case ('d' | 'D'):
        case Keypad.KEY_DELETE:
        case Keypad.KEY_BACKSPACE:
            delete();
            return true;
        default:
            return super.keyChar(c, status, time);
        }
    }
    
    public String getListName() {
        return _thisListName;
    }
    
    public void delete() {
        int i = Dialog.ask(Dialog.D_DELETE, "Delete " + _thisListName + "?");
        if(Dialog.DELETE == i) {
            Manager m = getManager();
            if(m != null)
                m.delete(this);
        }
    }

 

Here is the relevant code. The keyChar to catch the delete key and the location of the delete method are in the one custom Field class.

 

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Odd Field getManager() Issue

Hmmm...  Don't see any obvious problems with the code.  I'll try to debug it at home tonight - there might be something small and unexpected (as it is often the case with BlackBerry).

----------------------------------------------------------
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
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Odd Field getManager() Issue

Well, I've just created and tested the following field - with everything working as it should.  Check what you are doing differently.  I'm creating the first one with FOCUSABLE style bit, of course.

 

import net.rim.device.api.i18n.ResourceBundleFamily;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;

public class DeletableLabelField extends LabelField {
	private static int _fieldCount;

	public DeletableLabelField() {
		++_fieldCount;
	}

	public DeletableLabelField(Object arg0) {
		super(arg0);
		++_fieldCount;
	}

	public DeletableLabelField(Object text, long style) {
		super(text, style);
		++_fieldCount;
	}

	public DeletableLabelField(ResourceBundleFamily rb, int key) {
		super(rb, key);
		++_fieldCount;
	}

	public DeletableLabelField(Object text, int offset, int length, long style) {
		super(text, offset, length, style);
		++_fieldCount;
	}

	protected boolean keyChar(char c, int status, int time) {
		switch(c) {
		case ('d' | 'D'):
		case Keypad.KEY_DELETE:
		case Keypad.KEY_BACKSPACE:
			delete();
			return true;
		case ('a' | 'A'): {
			insert();
			return true;
		}
		default:
			return super.keyChar(c, status, time);
		}
	}

	public void delete() {
		int i = Dialog.ask(Dialog.D_DELETE, "Delete " + getText() + "?");
		if(Dialog.DELETE == i) {
			Manager m = getManager();
			if(m != null)
				m.delete(this);
		}
	}
	
	public void insert() {
		Manager m = getManager();
		if (m != null) {
			m.add(new DeletableLabelField(getText() + "_" + _fieldCount, FOCUSABLE));
		}
	}

}

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!