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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer
Accepted Solution

OnTouch event on Listfield item

I have made a listfield by extending a Vertical manager where i am adding number of Horizontal manager.The HFM contains an image and a Text.Now the thing is that i want to get the index of the row when i click it.The problem is that for the first row it gives me 0 which is correcnt,but for the 2nd row it gives me 2 instead of 1,same for 3rd it gives 4 instead of 2.Please help

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

Re: OnTouch event on Listfield item

Just to avoid confusion, what you seem to have created is not a ListField, which is a completely different UI component than a series of HFMs added to a VFM.

 

You seem to be using getFieldIndex() on the VFM.  If all you had added were the HFM, then I would expect the indexes to go up by one. The fact that they go up by 2 indicates that you have added something else, like a NullField.  So I would check your code to confirm which Manager you are getting the Field index from and what else you add to that Manager. 

Highlighted
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

No i havent use added any other field in Vfm except my hfm.And i am doing this from touchevent

getLeafFieldWithFocus().getManager().getIndex()

 

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

Re: OnTouch event on Listfield item

And which Manager is this getting the index for? 

 

In my experience, the Indexes don't lie.  The fact that it appears to be wrong would suggest a logic error in this approach. 

 

The debugger is your Friend here.  But split the statement up so you can check all components, say

Field focusField = getLeafWithFocus();

Manager focusManager = focusField.getManager();

Manager focusManagerManager = focusManager.getManager();

int focusIndex = focusManager.getIndex();

System.out.println("Focused on: " + focusField.toString() + " in " + focusManager.toString() + ", which is in: " + focusManagerManager.toString() + " at index: " + focusIndex);

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

Yes i have found the problem actualy i am also adding a seperator field to the vfm after adding each hfm

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

I solved it like this 

this.getLeafFieldWithFocus().getManager().getIndex())/2

 thnx for ur suggestion

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

Re: OnTouch event on Listfield item

OK, please mark this as solved.  Instructions in the Help link near the top of the screen. 

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

ye si already liked and accepted as solution ur First reply