11-23-2012 04:42 AM
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
Solved! Go to Solution.
11-23-2012 05:09 AM
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.
11-23-2012 05:14 AM
No i havent use added any other field in Vfm except my hfm.And i am doing this from touchevent
getLeafFieldWithFocus().getManager().getIndex()
11-23-2012 05:49 AM
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);
11-23-2012 05:57 AM
Yes i have found the problem actualy i am also adding a seperator field to the vfm after adding each hfm
11-23-2012 06:08 AM
I solved it like this
this.getLeafFieldWithFocus().getManager().getIndex())/2
thnx for ur suggestion
11-23-2012 06:09 AM
OK, please mark this as solved. Instructions in the Help link near the top of the screen.
11-23-2012 06:24 AM
ye si already liked and accepted as solution ur First reply