B4J Question [B4X] B4XTable Double Click

Erel

Administrator
Staff member
Licensed User
There are two standard click events: CellClicked and CellLongClicked (right click in B4J).

If you want to handle double clicks then you will need to do some work.
You need to add a transparent panel to each of the cells. In this example I'm adding them to a column that is stored in a global variable named column:
B4X:
column = B4XTable1.AddColumn("Number Example 3", B4XTable1.COLUMN_TYPE_NUMBERS)
Dim data As List = su.LoadCSV2(File.DirAssets, "us_counties.csv", ",", headers)
B4XTable1.MaximumRowsPerPage = 20
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
For i = 1 To column.CellsLayouts.Size - 1
   Dim p As B4XView = column.CellsLayouts.Get(i)
   Dim Touch As B4XView = xui.CreatePanel("Touch")
   Touch.Color =xui.Color_Transparent
   Touch.Tag = i - 1
   p.AddView(Touch, 0, 0, p.Width, p.Height)
Next
B4XTable1.SetData(data)

Sub B4XTable1_DataUpdated
   For i = 1 To column.CellsLayouts.Size - 1
       Dim p As B4XView = column.CellsLayouts.Get(i)
       Dim Touch As B4XView = p.GetView(1)
       Touch.SetLayoutAnimated(0, 0, 0, p.Width, p.Height)
   Next
End Sub

Private Sub Touch_MouseClicked (EventData As MouseEvent)
   Dim p As B4XView = Sender
   Dim RowNumber As Int = p.Tag
   Dim RowId As Long = B4XTable1.VisibleRowIds.Get(RowNumber)
   If RowId > 0 Then
       Dim value As String = B4XTable1.GetRow(RowId).Get(column.Id)
       If EventData.ClickCount = 2 Then
           Log($"Double click: ${value}"$)
       Else
           Log($"Single click: ${value}"$)
       End If
   End If
   EventData.Consume
End Sub
 

jimmyF

Active Member
Licensed User
You can also do this and it works for me.

B4X:
'Put this declaration In Process Globals
'Dim WaitClick As Byte
  
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    If WaitClick = 1 Then
        WaitClick = 2
        Return
    End If
 
    WaitClick = 1

    Sleep (250)   'adjust for how fast you want the Double Click/Tap to be.
    
    If WaitClick = 1 Then
        Log ("Single")
    Else
        Log ("Double")
    End If

    WaitClick = 0
end Sub
EDIT: Sorry, this is what works for me in B4A. Not tried in B4J
Should be fine though
 
Last edited:
Top