B4A Library [B4X] CLVItemToolbox - custom view.

Updated to v. 1.31 03/30/2022
Fixed: ItemRemoved declaration correct.

Updated to v. 1.30
Added internal dialog (optional) to ask for confirmation of removal and many properties about this, included one to choose whether to use this dialog or not.
Added the CLVItemToolbox1_ItemRemoved (Value As Object) event; this will be triggered if the internal dialog is used, otherwise the other event will trigger, CLVItemToolbox1_Click.
See post #13 and next.

UPDATED TO V. 1.20
Added the ability to blink icons (being able to set which ones) and temporarily disable blinking of the entire item.
You can also set how many times an icon should blink and the duration of the single blink.
The attached sample project has also been updated.


I'm thinking maybe a custom view like this would be useful:

Senza nome.png


to be added to each item of a CustomListView.

The icons would serve, in order, to:

- select the item
- modify the item
- delete the item.

I was thinking... then I developed it.

It's free but don't forget I need coffee to live ;)


It's a custom view for B4A, B4J, B4I; a B4XLib that you should add to the Additional Libraries folder.


I shouldn't be doing these things overnight; in fact, I shouldn't do them at all 😄
1.gif


B4A-Android

[Another example and discussion here]

I think its purpose and use are simple; when you create an item layout for your xCustomListView in the Designer, add this CLVItemToolbox like any other view.

You can choose which of the 3 icons to display (Check, Edit, Remove) and change the images if you don't like them.
1.gif


By clicking/tapping on the CLVItemToolbox the Click event will be triggered, which will receive as parameters the type of action (CHECKED, UNCHECKED, EDIT, REMOVE) and the base of the custom view, which will be useful for obtaining the index of the relative item:
B4X:
Private Sub CLVItemToolbox1_Click(Action As String, Base As B4XView)
    Dim ItemIndex As Int
    ItemIndex = CustomListView1.GetItemFromView(Base)

    Select Action
        Case CLVItemToolbox1.CHECKED
        Case CLVItemToolbox1.UNCHECKED
        Case CLVItemToolbox1.EDIT
        Case CLVItemToolbox1.REMOVE
    End Select
End Sub

Library and sample project are attached.
 

Attachments

  • CLVItemToolboxEx.zip
    14.2 KB · Views: 70
  • CLVItemToolboxLIB_1_30.zip
    12 KB · Views: 74
  • CLVItemToolboxLIB_1_31.zip
    12 KB · Views: 50
Last edited:

AnandGupta

Well-Known Member
Licensed User
Longtime User
Lucas, you have opened a door, which shows us path that complex views like this can be made, if you know the rules of the land (B4X).
This will greatly help begineers and experts alike to learn.
 

LucaMs

Expert
Licensed User
Longtime User
Note for those wishing to use the source code.

There are 3 Panels superimposed on the 3 ImageView. These are no longer needed, I put them in because I initially used 3 B4XImageViews, which don't have the Click event.

I will "correct" this thing (the CV works anyway, of course) and I would also like to do another one: temporarily stop the CLV from blinking (if I can do it!) and, instead, make the 3 icons blink.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I would also like to do another one: temporarily stop the CLV from blinking (if I can do it!)
xCustomListView does not have a property to disable blinking, but you can use a trick: just set the "Pressed color" to Transparent.

Now comes the hard part (Erel, help please 😁)...

how to get the xCLV parent of any View inserted in an item?
A recursive routine will be needed and maybe that won't be enough.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
There is no built-in reference from any of the views to the CLV instance class. You will need to add one yourself. For example by passing the CLV instance to a method in your class.
Thank you, Erel; done.

Updated to v. 1.20.
Added the ability to blink icons (being able to set which ones) and temporarily disable blinking of the entire item.
You can also set how many times an icon should blink and the duration of the single blink.
The attached sample project has also been updated.
 

Mahares

Expert
Licensed User
Longtime User
Can you show what you are supposed to do with these actions. In other words, where is the code for all these actions, that the toolBox is supposed to perform:
B4X:
 Select Action
        Case CLVItemToolbox1.CHECKED
        Case CLVItemToolbox1.UNCHECKED
        Case CLVItemToolbox1.EDIT
        Case CLVItemToolbox1.REMOVE
    End Select
 

Xfood

Expert
Licensed User
I believe that the toolbox raises this event, so then everyone writes the code based on the event raised by the toolbox, by clicking the corresponding button in the toolbox
 

LucaMs

Expert
Licensed User
Longtime User
Can you show what you are supposed to do with these actions. In other words, where is the code for all these actions, that the toolBox is supposed to perform:

It's as @Xfood wrote, of course; what to do depending on which icon is touched is a developer's decision using this CV.
It is as if you were asking:
"I have Button1 view and Button1_Click: what should I write in Button1_Click?"
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Can you show what you are supposed to do with these actions. In other words, where is the code for all these actions, that the toolBox is supposed to perform:
Your question, @Mahares, to which @Xfood and I answered, made me think of a variant.

Already now it is possible to change the images of the 3 icons, for example change the trash icon, if you don't like the one I chose.
It would be nice to be able to change the name of the action associated with each icon as well. For example, you might have an icon that is interpreted as:
"duplicate this item"
copy-icons-14.png

or one to copy the item (its value) to the clipboard
copy-to-clipboard-4212.png

It seems to me that these may be actions that the developer might want to add to his items.

What do you think?

However, having obtained 390 views:
1648076242959.png

but "only" 16 Likes (thanks to all of you) and not a single coffee 😄 :confused:... makes me think that other changes, which cost time, may not be worth making (another idea could be to allow a variable number of icons, which is not so easy).
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
everyone writes the code based on the event raised by the toolbox
It's as @Xfood wrote, of course; what to do depending on which icon is touched is a developer's decision using this CV.
True, but I can accomplish the same thing without the need of the CLVItemToolBox event.
nstead of:
B4X:
Select Action
        Case CLVItemToolbox1.CHECKED
        Case CLVItemToolbox1.UNCHECKED
        Case CLVItemToolbox1.EDIT
        Case CLVItemToolbox1.REMOVE
            Msgbox2Async("Are you sure?", "Delete Entry", "Yes", "Cancel", "No", Null, False)
            Wait For Msgbox_Result (result As Int)
            If result = DialogResponse.POSITIVE Then
                CustomListView1.RemoveAt(ItemIndex)
            End If
    End Select
I can use the label click event:
B4X:
Sub lblItem_Click
    Dim index As Int = CustomListView1.GetItemFromView(Sender)
    Msgbox2Async("Are you sure?", "Delete Entry", "Yes", "Cancel", "No", Null, False)
    Wait For Msgbox_Result (result As Int)
    If result = DialogResponse.POSITIVE Then
        CustomListView1.RemoveAt(index)
    End If
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
I can use the label click event:
Even more simply you could use the CLV events ItemClick or ItemLongClick and decide if these actions will be used to ask to remove the item or open a dialog to edit it or to select the item or perhaps to open a contextual help, but.... the user doesn't know in advance, you should write a help. Instead, the icons immediately make it clear what he can do with an item.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Even more simply you could use the CLV events ItemClick or ItemLongClick and decide if these actions will be used to ask to remove the item or open a dialog to edit it or to select the item or perhaps to open a contextual help, but.... the user doesn't know in advance, you should write a help. Instead, the icons immediately make it clear what he can be done with an item.
However, since to suspend the blinking / flashing of the item I had to make the developer pass the CLV to the CLVItemToolbox (#5), I could also write the code directly in the library to ask for confirmation of the removal of the item; it would be an extra convenience.
 

LucaMs

Expert
Licensed User
Longtime User
However, since to suspend the blinking / flashing of the item I had to make the developer pass the CLV to the CLVItemToolbox (#5), I could also write the code directly in the library to ask for confirmation of the removal of the item; it would be an extra convenience.
Done but not yet added to the B4Xlib (CLVItemToolbox, of course). "Unfortunately", the internal dialog will not be able to display a text relating to the item to be removed, nor would it be useful for the end user to see its index number. I do not like this.

I mean that such a dialog should ask for something like:
"Do you want to remove John?" and not "Do you want to remove the item?", generically.

I created a property to set whether to use the confirmation dialog inside the CLVItemToolbox (and the properties for the texts of the dialog) or not. Also, I added the CLVItemToolbox1_ItemRemoved (ItemIndex As Int) event; this will be triggered if the internal dialog is used, otherwise the other event will trigger, CLVItemToolbox1_Click.

The internal dialog is shown.
1.gif
https://youtube.com/shorts/96V8wMwai5E?feature=share
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Done but not yet added to the B4Xlib (CLVItemToolbox, of course). "Unfortunately", the internal dialog will not be able to display a text relating to the item to be removed, nor would it be useful for the end user to see its index number. I do not like this.

I mean that such a dialog should ask for something like:
"Do you want to remove John?" and not "Do you want to remove the item?", generically.

I created a property to set whether to use the confirmation dialog inside the CLVItemToolbox (and the properties for the texts of the dialog) or not. Also, I added the CLVItemToolbox1_ItemRemoved (Value As Object) event; this will be triggered if the internal dialog is used, otherwise the other event will trigger, CLVItemToolbox1_Click.
Updated to v. 1.30
Added internal dalog to ask for confirmation of removal and many properties about this, included one to choose whether to use this dialog or not.
Added the CLVItemToolbox1_ItemRemoved (ItemIndex As Int) event; this will be triggered if the internal dialog is used, otherwise the other event will trigger, CLVItemToolbox1_Click.


I shouldn't be doing these things overnight; in fact, I shouldn't do them at all 😄
1.gif
 
Last edited:
Top