B4J Code Snippet TableView Scroll via Code

TableView Scroll via Code

Often a TableView consists of more Rows than can be displayed in it and it is necessary to scroll the Rows to see all of the content of the TableView.

The TableView.ScrollTo(row) feature will scroll the Row to the top of the TableView if there is enough Items in the TableView.

The DemoTV TableView used here has ten (10) Rows Visible in the TableView. However, there are twenty-five (25) Rows in the TableView items.

The following code will Scroll The TableView one row at a time after the Selected Row reaches Row nine (8).

B4X:
' Process and Display Data and prepare Next Row for the DemoTV
Sub DoSomething
    Dim obj() As Object
    obj = DemoTV.SelectedRowValues
    RowLbl.Text = TVIdx
    MeetLbl.Text = obj(1)
   
    ' Set Next Row Index for Selection
    TVIdx = TVIdx + 1
   
    ' There are 10 items viewable in the DemoTV
    ' Scrolls after a number of Records are displayed
    ' 8 Recorda are chosen in this example
    If TVIdx > 8 Then
        ' ScrollTo moves the Selected Row to the TOP of the TableView
        ' providing there are enough items in the TableView
        DemoTV.ScrollTo(TVIdx - 8)
    End If
   
    ' Check for more rows and update Selected Row and Enable Timer
    If TVIdx < DemoTV.Items.Size Then
        ' Select the Next Index
        DemoTV.SelectedRow = TVIdx
        SeqTimer.Enabled = True
    End If
End Sub
 

Attachments

  • TVScroll.zip
    3.2 KB · Views: 375
Top