Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ajaypaudel
Visitor

get focused index in labellist

Hello how can we get itemfocused index in labellist like in rowlist?
0 Kudos
5 REPLIES 5
norcaljohnny
Roku Guru

Re: get focused index in labellist

You can use many methods but I normally use a variable something like this so I can increment elsewhere in the component or as text..

m.currentItem = m.postergrid.itemFocused
m.myLabel.text = m.currentItem

This is assuming I have a topNode named m.postergrid
0 Kudos
ajaypaudel
Visitor

Re: get focused index in labellist

"norcaljohnny" wrote:
You can use many methods but I normally use a variable something like this so I can increment elsewhere in the component or as text..

m.currentItem = m.postergrid.itemFocused
m.myLabel.text = m.currentItem

This is assuming I have a topNode named m.postergrid

Now the problem is it shows focused on different item and when we print then the value is different and when we click up button and gives invalid value and when clicking down after certain value again it gives invalid value, how can we solve that issue?
0 Kudos
speechles
Roku Guru

Re: get focused index in labellist

            handled = false
            if m.labellist.isInFocusChain() and press
                if key = "up"
                    if m.labellist.itemFocused = 0
                        m.labelist.jumpToItem = m.labellist.content.getChildCount()-1 
                        m.labellist.animateToItem = m.labellist.content.getChildCount()-1 
                    else
                        m.labellist.jumpToItem = m.itemFocused - 1
                    end if
                    handled = true
                else if key = "down"
                    if m.labellist.itemFocused = m.labellist.content.getChildCount()-1 
                        m.labellist.jumpToItem = 0
                        m.labellist.animateToItem = 0
                    else
                       m.labellist.jumpToItem = m.itemFocused + 1
                    end if
                    handled = true
                else if key = "OK"
                    handleLabellistOKpress(m.labellist.itemSelected)
                    handled = true
                end if
            end if
            return handled

( the reason for both jumpToItem and animateToItem is because I have no idea how large the viewport is you give your labellist. jumpToItem only jumps to the first/last item visible in your viewport. animateToItem will move to the first/last of your labellist and scroll to it )

To control the up/down and have it wrap you would do something like the above. 
In a labellist itemFocused for focused item. itemSelected for item chosen. Are you mixing these up?
0 Kudos
ajaypaudel
Visitor

Re: get focused index in labellist

"speechles" wrote:
            handled = false
            if m.labellist.isInFocusChain() and press
                if key = "up"
                    if m.labellist.itemFocused = 0
                        m.labelist.jumpToItem = m.labellist.content.getChildCount()-1 
                        m.labellist.animateToItem = m.labellist.content.getChildCount()-1 
                    else
                        m.labellist.jumpToItem = m.itemFocused - 1
                    end if
                    handled = true
                else if key = "down"
                    if m.labellist.itemFocused = m.labellist.content.getChildCount()-1 
                        m.labellist.jumpToItem = 0
                        m.labellist.animateToItem = 0
                    else
                       m.labellist.jumpToItem = m.itemFocused + 1
                    end if
                    handled = true
                else if key = "OK"
                    handleLabellistOKpress(m.labellist.itemSelected)
                    handled = true
                end if
            end if
            return handled

( the reason for both jumpToItem and animateToItem is because I have no idea how large the viewport is you give your labellist. jumpToItem only jumps to the first/last item visible in your viewport. animateToItem will move to the first/last of your labellist and scroll to it )

To control the up/down and have it wrap you would do something like the above. 
In a labellist itemFocused for focused item. itemSelected for item chosen. Are you mixing these up?

Let me explain you, 
we have all the channel name list and 
m.list.ObserveField("itemFocused", "onItemFocused")
m.list.ObserveField("itemSelected", "OnItemSelected")
for on focus and on selected and on onItemFocused function we have done
row = m.list.currFocusRow

  col=  m.list.currFocusSection
section =  m.list.content.getChild(col)
channel=section.getChild(row)
here it gives the correct data upto the data showing on the monitor screen and when i click up and below the monitor screen it gives wrong data or invalid 
0 Kudos
speechles
Roku Guru

Re: get focused index in labellist

In your onKeyEvent when you navigate around make sure to check you don't fall out of bounds. Go by getChildCount()-1 and use that as the max for each col/row. Then use zero to tell the top. Don't let yourself go out of bounds or if you do then wrap to bottom and vice versa. Look above to the labellist code I gave above to see how I wrap there top/bottom and do the same. You can also do the same and wrap left/right right/left through the columns edges. What does your onKeyEvent look like?
0 Kudos