B4J Question [SOLVED] B4XFloatTextField. How to add ContextMenu in run time?

Dadaista

Active Member
Licensed User
Hi

Adding context menu to a B4XFloatTextField in designer is not working

How can I add it in run time?

Thx in advance
 

Dadaista

Active Member
Licensed User
Can you explain what you are trying to do please ?
Of course

In Images

TextField Control

2021-03-31 (1).png



Display

2021-03-31.png



B4XFloatTextField control

2021-03-31 (1).png


Display

2021-03-31 (2).png


Is it clear? ;)
 
Upvote 0

DaleA

Member
I think the question is, in a B4XFloatTextField, how do you override the system's context menu with a code-supplied one rather than setting it in the Designer?
 
Upvote 0

Dadaista

Active Member
Licensed User
Well... my english is very limited

The question is... I write in designer a context menu. That context menu is not showed.
 
Upvote 0

Dadaista

Active Member
Licensed User
Thx @moster67
I will take a look...
The problem than I can see... I only want to show context menu when Right click. If left click, context menu is showed
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
B4X:
 SetContextMenu(B4XFloatTextField1, Array("AAA", "BBB", "CCC"), "B4XFloatTextField1")


Sub B4XFloatTextField1_Action
    Dim mi As MenuItem = Sender
    Log(mi.Text)
End Sub

Sub SetContextMenu (Field As B4XFloatTextField, MenuItems As List, EventName As String)
    #if B4J
    Dim tf As TextField = Field.TextField
    Dim ctxt As ContextMenu
    ctxt.Initialize("")
    For Each s As String In MenuItems
        Dim mi As MenuItem
        mi.Initialize(s, EventName)
        ctxt.MenuItems.Add(mi)
    Next
    tf.ContextMenu = ctxt
    #End If
End Sub
Note that if this is a password field and you want to include the reveal feature then you will need to recreate the menu when the PasswordRevealChanged event is raised.
 
Upvote 0

Dadaista

Active Member
Licensed User
Thanks @Erel

With your code I can not get same context menu showed in a TextField control. So I have decided to keep a Textfield control with context menu made in designer and property visible = false and make property ContextMenu of B4XFloatTextField = TextField.ContextMenu
 
Upvote 0
Top