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
Super Contributor
arunbiet
Posts: 351
Registered: ‎06-22-2010
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

Please use plain text.
Developer
peter_strange
Posts: 19,508
Registered: ‎07-14-2008

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. 

Please use plain text.
Super Contributor
arunbiet
Posts: 351
Registered: ‎06-22-2010
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()

 

Please use plain text.
Developer
peter_strange
Posts: 19,508
Registered: ‎07-14-2008

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);

Please use plain text.
Super Contributor
arunbiet
Posts: 351
Registered: ‎06-22-2010
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

Please use plain text.
Super Contributor
arunbiet
Posts: 351
Registered: ‎06-22-2010
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

I solved it like this 

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

 thnx for ur suggestion

Please use plain text.
Developer
peter_strange
Posts: 19,508
Registered: ‎07-14-2008

Re: OnTouch event on Listfield item

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

Please use plain text.
Super Contributor
arunbiet
Posts: 351
Registered: ‎06-22-2010
My Carrier: blackberry developer

Re: OnTouch event on Listfield item

ye si already liked and accepted as solution ur First reply

Please use plain text.