B4J Question Long click in CLV

Tim Chapman

Active Member
Licensed User
Longtime User
In the attached code, I am trying to make a long click work on the label or panel. (See the layout file).
How do I do this?
 

Attachments

  • CLVExample.zip
    5 KB · Views: 41

William Lancee

Well-Known Member
Licensed User
Longtime User
Since there is no LongClick event in B4J, I would suggest using right click

B4X:
Private Sub label1_MouseClicked(Ev As MouseEvent)
    If Ev.SecondaryButtonPressed Then
        Dim lbl As B4XView = Sender
        lbl.Text = "You called?"
    End If
    Ev.Consume
End Sub

If you want to simulate a long click you need to use MousePressed and MouseReleased to time the click.
Take a look as @klaus booklet BasicLanguage around page 80.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Similarly for the panel. If you want to know which row was clicked, add that info as a label1.tag.

B4X:
Private Sub CreateListItem(Text As String, Width As Int, Height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("panel")      'Change this
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
    'Note that we call DDD.CollectViewsData in CellItem designer script. This is required if we want to get views with dd.GetViewByName.
    dd.GetViewByName(p, "Label1").Text = Text
    dd.GetViewByName(p, "Label1").Tag = clv1.size + 1    'Add this
    Return p
End Sub

Private Sub panel_MouseClicked(Ev As MouseEvent)
    If Ev.SecondaryButtonPressed Then
        Dim pnl As B4XView = Sender
        Dim lbl As Label = pnl.GetView(0).GetView(0)
        lbl.Text = "Row: " & lbl.Tag
    End If
    Ev.Consume
End Sub

Private Sub label1_MouseClicked(Ev As MouseEvent)
    If Ev.SecondaryButtonPressed Then
        Dim lbl As B4XView = Sender
        lbl.Text = "Row: " & lbl.Tag
    End If
    Ev.Consume
End Sub
 
Upvote 1

William Lancee

Well-Known Member
Licensed User
Longtime User
Yes. The consequence of the different pointing devices.
You obviously know about #If B4J #Else #End If tags.

I did make a version for LongClick, but tying it out made it obvious that a mouse is not a finger.

B4X:
Private Sub label1_MousePressed(Ev As MouseEvent)
    mouseDownTime = DateTime.Now
End Sub

Private Sub label1_MouseReleased(Ev As MouseEvent)
    If DateTime.Now - mouseDownTime > 500 Then
        Log(DateTime.Now - mouseDownTime)
        Dim lbl As B4XView = Sender
        lbl.Text = "Row: " & lbl.Tag
        Dim chk As CheckBox = lbl.Parent.GetView(1)
        chk.Checked = (chk.Checked = False)
        Ev.Consume
    End If
End Sub

Private Sub panel_MousePressed(Ev As MouseEvent)
    mouseDownTime = DateTime.Now
End Sub

Private Sub panel_MouseReleased(Ev As MouseEvent)
    If DateTime.Now - mouseDownTime > 500 Then
        Dim pnl As B4XView = Sender
        Dim lbl As Label = pnl.GetView(0).GetView(0)
        lbl.Text = "Row: " & lbl.Tag
        Dim chk As CheckBox = pnl.GetView(0).GetView(1)
        chk.Checked = (chk.Checked = False)
        Ev.Consume
    End If
End Sub
 
Upvote 0
Top