Android Question CLVTree add clickable text with CSBuilder

mike1967

Active Member
Licensed User
Longtime User
Hello
code:
Dim clicktext As String
        clicktext="Edit"
        
        cs.Initialize.size(13).Bold.Append("N.ro Interno:").Pop.Append(dispositivo.Get("numero")).Append(CRLF).Bold.Append("Matricola:").Pop.Append(dispositivo.Get("matricola")).Append(CRLF).Bold.Append(dispositivo.Get("descrizione")).PopAll.Append(CRLF).Clickable("edit",clicktext).Append(clicktext).PopAll
        Dim item2 As CLVTreeItem= Tree.AddItem(item,cs,LoadBitmap(File.DirAssets,"file-alt.png"),"")
        Dim Index As Int=CustomListView1.GetItemFromView(item2.InternalPanel)
        cs.EnableClickEvents(CustomListView1.GetPanel(Index).GetView(0))
, is possible to add an item to CLVTree with clickable text by CSBuilder ? If Yes Can Provide Me a sample ? Thanks in advances

Error view should be initializate.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1677135256073.png


The challenge here is that CLVTree creates the views when needed and reuses them when possible, so you can't simply access the views.
The solution is to use the source code of CLVTree and add:
B4X:
Dim cs As CSBuilder 'ignore
cs.EnableClickEvents(lbl)
In the code that creates new UI items.

See the attached B4A-only project.
 

Attachments

  • Project.zip
    235.1 KB · Views: 67
Upvote 0

mike1967

Active Member
Licensed User
Longtime User
View attachment 139654

The challenge here is that CLVTree creates the views when needed and reuses them when possible, so you can't simply access the views.
The solution is to use the source code of CLVTree and add:
B4X:
Dim cs As CSBuilder 'ignore
cs.EnableClickEvents(lbl)
In the code that creates new UI items.

See the attached B4A-only project.
with this modify the events CustomListView1_ItemClick (Index As Int, Value As Object) is not raised. What About ?
 
Upvote 0

mike1967

Active Member
Licensed User
Longtime User
True. The label which fills the item catches the click event now.

You can add an empty clickable span at the end and use it instead of the ItemClick event:
B4X:
.Clickable("cs", "ItemClick").Append(" ").PopAll
Thanks works. How to retrive the item value in order to add sub items with this method Instead of CustomListView1_ItemClick (Index As Int, Value As Object) ?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
How to retrive the item value in order to add sub items with this method Instead of CustomListView1_ItemClick (Index As Int, Value As Object) ?
Why do you need a clickable span in the title. Why not use the CustomListView1_ItemClick event and based on its value execute your wish. FOr instance:
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
Dim item As CLVTreeItem = Value
 Dim s As String = item.Text
If s.tolowercase.contains("test") Then
        Dim i As Intent
        i.Initialize(i.ACTION_VIEW, "https://www.google.com")
        StartActivity(i)
    End If
End Sub
You probably have a reason to use clickable, but can you tell us why. I see that you have a follow up thread for Erel to help you with.
 
Upvote 0
Top