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: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR
Accepted Solution

Adding fields to a manager on different button clicks

[ Edited ]
if (field == buttonField && label.equals("First")) {
	    	LabelField label = new LabelField("1");
		add(label);
		buttonField.setLabel("Last");
} else if (field == buttonField && label.equals("Last")) { buttonField.setLabel("First"); labelField2 = new LabelField("2"); add(labelField2); labelField3 = new LabelField("3"); add(labelField2); }

Here is an example of my FieldChangeListener. It is clear what it does (clear even to me  ). It simply adds fields - one field at first button clicks, and another two - at the second click.

What I want it to do is to add these fiels to a manager - no matter vertical or horizontal, I just need to get the concept of how it should be done. The idea is to construct a manager at first button click and to add labelField to it. When the second click happens, I need this manager to add another field(s), e.g. like in my code example.

Could you please indicate the way to achieve this? It might be smth very obvious, yet I am missing it.

EDIT: spelling mistakes, sorry...

EDIT2: Can this be achieved via setter/getter?

Developer
Posts: 48
Registered: ‎06-02-2013
My Device: 9780
My Carrier: MTS UKR

Re: Adding fields to a manager on different button clicks

Setter / getter did the trick.

if (field == buttonField && label.equals("First")) {
	    	getHFM();
                LabelField label = new LabelField("1");
		setHFM().add(label);
		buttonField.setLabel("Last");
}
else if (field == buttonField && label.equals("Last")) {
		buttonField.setLabel("First");
		labelField2 = new LabelField("2");
		setHFM().add(labelField2);
		labelField3 = new LabelField("3");
		setHFM().add(labelField2);
}

public HorizontalFieldManager getHFM(){
		hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
		add(hfm);
		return hfm;
}
public HorizontalFieldManager setHFM() {
		return hfm;
}