Android Tutorial [B4X] B4XTable - Multiple rows selection

Discussion in 'Tutorials & Examples' started by Erel, Feb 6, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This example depends on B4XTable v1.02+ and B4XCollections.

    [​IMG]

    It is quite simple to implement custom selection logic.

    Step #1: The Selection Color property in the designer should be set to transparent. This will disable the default cell click animation.

    Step #2: We maintain a B4XSet with the selected rows ids. This set is updated in the CellClicked event:
    Code:
    Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
       
    Dim Selected As Boolean
       
    If SelectedRows.Contains(RowId) Then
           SelectedRows.Remove(RowId)
           Selected = 
    False
       
    Else
           SelectedRows.Add(RowId)
           Selected = 
    True
       
    End If
       
    Dim Index As Int = B4XTable1.VisibleRowIds.IndexOf(RowId) 'Find the index of the visible row
       SetRowColor(Index, Selected) 'Set its color
    End Sub
    Step #3: Whenever the data is updated, we need to go over the visible rows and update their visual state:
    Code:
    Sub B4XTable1_DataUpdated
       
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
           
    Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
           SetRowColor(i, SelectedRows.Contains(RowId))
       
    Next      
    End Sub
    A B4J example is attached.
     

    Attached Files:

    GMan, koaunglay, ocalle and 5 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice