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
Contributor
Posts: 18
Registered: ‎05-17-2011
My Device: Blackberry 8520
My Carrier: Koodo
Accepted Solution

FieldChangeListener for an element in GridFieldManager

Hi,

 

 

I have a GridFieldManager loaded with bunch of elements in type of horizontalFieldManagers. I noticed that after adding those managers to GridFieldManager and calling getFieldAtIndex to my GridFieldManager, it will return me a FIELD. Can I set a FieldChangeListener to this returned field? What I know is I could not do it to HorizontalFieldManager. But can I do it to this returned field?

 

My intention is to create a list, that whenever you click one of the element, it will change the content of the gridfieldmanager.

 

Thank you very much!

Developer
Posts: 146
Registered: ‎07-24-2008
My Device: none
My Carrier: none

Re: FieldChangeListener for an element in GridFieldManager

If you look in to the API for Field class, you can set FIeldChangeListener to any field.
FieldChangeListener getChangeListener()
Retrieves the current change listener.
void setChangeListener(FieldChangeListener listener)
Specifies a listener for changes to this field.

Use the above methods for elements in GridFIeldManager, it should work.

Ankit
Thanks & Regards,
Ankit Dubey
Module Lead Software Engineer, mLabs
Impetus InfoTech (India) Pvt. Ltd.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: FieldChangeListener for an element in GridFieldManager

If you have added HFM to your GridFieldManager, than when you ask for a Field using getFieldAtIndex(..), you will get one of your HFMs.  I have never tried setting a change listener to a Manager, but you suggest it doesn't work and I would agree it is unlikely to work, and it doesn't seem to be what you want to do anyway.  So once you d a getFieldAtindex, you could check to see if the Field you got back is actually a Manager, and then use getFieldAtIndex on the Manager to find the real Fields.

 

However I suspect it is easier to add the change listener when you first create the Field and add them, rather than trying to do it once the Fields are added.

Contributor
Posts: 18
Registered: ‎05-17-2011
My Device: Blackberry 8520
My Carrier: Koodo

Re: FieldChangeListener for an element in GridFieldManager

Hi Peter,

 

so what I have right now is:

A GridFieldManager filled with HorizontalFieldManagers as elements.

Each HorizontalFieldManager has bunch of fields.

I used getFieldAtIndex to get one of the HFM, and then use another getField to get one fo the Fields inside the HFM. I set the FieldChangeListener to that one field. And it doesnt work.

 

Do I have to set every single Fields inside the HFM to have the same FieldChangeListener?

Is my question clear enough? Thanks a lot.

Contributor
Posts: 18
Registered: ‎05-17-2011
My Device: Blackberry 8520
My Carrier: Koodo

Re: FieldChangeListener for an element in GridFieldManager

I tried to set the same Listener to all fields in that HFM but still doesnot work.

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

Re: FieldChangeListener for an element in GridFieldManager

Does the change listener get invoked?

 

Some fields, like Buttons, will appreciate that a click is a 'change' event.  others, like EditFields, won't notice a click as change, and won't drive the change listener until you start changing the text, and others, like LabelFields, can't change, so won't, by themselves, ever drive a change listener. 

Contributor
Posts: 18
Registered: ‎05-17-2011
My Device: Blackberry 8520
My Carrier: Koodo

Re: FieldChangeListener for an element in GridFieldManager

oh so you have to invoke it manually? I never invoke it. I just declare it and set it to the field.

FieldChangeListener goToUserProfile = new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				for(int l = 0; l < _peopleDisplayManager.getRowCount(); l++)
				{
					if (field.equals(_peopleDisplayManager.getFieldAtIndex(l)))
					{
						
						_peopleDisplayManager.deleteAll();
						_peopleDisplayManager.add(new LabelField("hello"));
						break;
					}
				}
			}
		};	
		yow.setChangeListener(goToUserProfile);

 _peopleDisplayManager is a gridFieldManager,

 yow is a field from HFM in the gridFieldManager.

 

 

how do you invoke it manually? 

Thanks

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

Re: FieldChangeListener for an element in GridFieldManager

What sort of Field is yow?  What would change in it that it would think the listener might be interested in?

Contributor
Posts: 18
Registered: ‎05-17-2011
My Device: Blackberry 8520
My Carrier: Koodo

Re: FieldChangeListener for an element in GridFieldManager

yow is a bitmap field. I was planing that wheneve the element in GFM being clicked, the content of GFM is totally changed. Is that possible?

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

Re: FieldChangeListener for an element in GridFieldManager

Yes, but BitmapFields don't normally change so do not normally call the change listener.  You will have to implement this yourself for the Field.  This is easy, override navigationClick and touchEvent.  There are plenty of samples on this forum  search for Image button.