That's how it's supposed to work. When you get to the last category you wrap around to the first category, and vice-versa.
However, if you really want to confuse your Roku users and do something different when you reach the first or last category, then try something like this:
Sub Main ()
contentList = loadContent ()
ui = CreateObject ("roPosterScreen")
p = CreateObject ("roMessagePort")
ui.SetMessagePort (p)
ui.SetListNames (getNames (contentList))
prevIndex = 0
ui.SetContentList (contentList[prevIndex].Content)
ui.Show ()
While True
msg = Wait (0, p)
If Type (msg) = "roPosterScreenEvent"
If msg.IsListFocused ()
If prevIndex = contentList.Count () - 1 And msg.GetIndex () = 0
displayMessage ("Last Index Plus 1")
ui.SetFocusedList (contentList.Count () - 1)
Else If prevIndex = 0 And msg.GetIndex () = contentList.Count () - 1
displayMessage ("Last Index Minus 1")
ui.SetFocusedList (0)
Else
prevIndex = msg.GetIndex ()
ui.SetContentList (contentList [msg.GetIndex ()].Content)
ui.SetFocusedListItem (0)
End If
EndIf
Else If msg.IsScreenClosed ()
Exit While
End If
End While
End Sub
Function loadContent () As Object
contentList = [ {Name: "< Category 1", Content: [ {ShortDescriptionLine1: "List 1, Item 1"},
{ShortDescriptionLine1: "List 1, Item 2"},
{ShortDescriptionLine1: "List 1, Item 3"},
]
},
{Name: "Category 2", Content: [ {ShortDescriptionLine1: "List 2, Item 1"},
{ShortDescriptionLine1: "List 2, Item 2"},
{ShortDescriptionLine1: "List 2, Item 3"},
]
},
{Name: "Category 3 >", Content: [ {ShortDescriptionLine1: "List 3, Item 1"},
{ShortDescriptionLine1: "List 3, Item 2"},
{ShortDescriptionLine1: "List 3, Item 3"},
]
},
]
Return contentList
End Function
Function getNames (contentList As Object) As Object
names = []
For Each content In contentList
names.Push (content.Name)
End For
Return names
End Function
Function displayMessage (message As String) As Void
ui = CreateObject ("roMessageDialog")
p = CreateObject ("roMessagePort")
ui.SetMessagePort (p)
ui.SetTitle (message)
ui.AddButton (0, "OK")
ui.Show ()
Wait (0, p)
ui.Close ()
End Function