Author Topic: How to know the index of the item present in the grid i am clicking.  (Read 4272 times)

ysrikanth2011

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Hi ,

I have a  vertical scrollview which has items scrolling. I have added a grid under it and some sprites under the grid .
How to know Which item(index) that I am clicking now ?
I have seen the UIScrollView and UIGrid class , but I did not found any  supporting method .

Please let me know a possible way of doing this .

Thanks in Advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to know the index of the item present in the grid i am clicking.
« Reply #1 on: April 25, 2014, 10:07:42 AM »
Which item you are clicking on, or the index of the item? They are different things. UIGrid's GetChildList() gives you the list of children, and you can do IndexOf to find the index.

ysrikanth2011

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: How to know the index of the item present in the grid i am clicking.
« Reply #2 on: April 26, 2014, 06:39:28 AM »
I actually want to know the index of the item currently clicked. I know the method "UIGrid.GetChildList()"    but where is the "indexof()" method ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to know the index of the item present in the grid i am clicking.
« Reply #3 on: April 26, 2014, 03:15:43 PM »
Hmm... may not be in 3.5.8. Add this to BetterList:
  1.         /// <summary>
  2.         /// Return the index of the specified item.
  3.         /// </summary>
  4.  
  5.         public int IndexOf (T item)
  6.         {
  7.                 if (buffer == null) return -1;
  8.                 for (int i = 0; i < size; ++i) if (buffer[i].Equals(item)) return i;
  9.                 return -1;
  10.         }