B4A Library [Class] CheckList

Hi,

I created a class to manage a list with checkboxes (but not only, you can use it for any kind of list with rows). The layout is highly customizable and you can even extend a clicked item with extra content. You can rearrange the items programmatically or manually (drag & drop).

Tutorials: How they do #1, How they do #3

img1.jpg img2.jpg img3.jpg img4.jpg img5.jpg

v1.1: I added the ExtendItem function and an option to check the box when items are added

v1.2: I fixed the width problem (in a container like TabHost, the width property returns -1, so we have to use a different method to get the SV width) and, in the demo, a click on the extended item collapses now its content.

v1.3: I added a new function to add items without checkbox (AddItemNoChkbx) so you can use this class as a ListView replacement;
I changed the way it colors the selected item (now it complies to the default Android theme);
I added an option to color differently the extended item.

v1.4: I optimized the code a little bit and I added three functions:
AddCustomItem (adds your own layout to the list);
AdjustBitmap (resizes the bitmap to fit the given dimensions);
GetFirstText (returns the first label text found for the given ID).

v1.5: I simplified and improved the management of extended items (I also fixed a bug). Unfortunately, that could break existing code.
Inspired by the class CustomListView, I added a parameter to Initialize: DividerHeight (if you want to put a colored divider between items) and several functions:
- NumberOfItems
- getHeight
- JumpToPosition
- JumpToItem
- CollapseItem
- HasExtraContent
- ExtendedItemID

v1.6:
Now, you can define the color of checked items and the background color (transparent by default).
I added two (very fast) functions:
- JumpToView (scrolls the list to the given view)
- FindPanelContaining (returns the panel containing the given view)
I added another example.

v2.0:
I added more than 10 new functions (MoveItem, RemoveItemAt, SwapItems, SortItems, ReplaceItem, ApplyColors, CreateTextList, etc.). See post #21 for complete list;
I changed the ID type (formerly Int) to Object (that shouldn't break the existing code);
I added the Drag & Drop feature;
I optimized JumpToPosition (a lot quicker now);
I fixed a bug with colors.

v2.1:
I added functions to filter the list;
I added CreateIntegerList to ease the sorting and filtering of integer values;
Now you can change the item height in ReplaceItem.

v2.2:
I fixed a bug (BackgroundColor was not applied to new items)
I added new functions:
- FindPanelWithID(ID As Object) As Object
- SetOnPaintListener(SubName As String)
- Repaint(pnlItem As Panel)
I renamed ApplyColors to RepaintAllItems

v2.21:
I changed an incorrect declaration in the demo #1 and #2.
The class is now compatible with the obfuscation option.

v2.22:
The class no longer displays warnings with B4A v2.7x.
All examples are now compatible with the obfuscation option.

Complete list of functions here

Fred

PS: you need the Reflection Lib
 

Attachments

  • CheckList v2.22.zip
    60.2 KB · Views: 2,362
Last edited:

cstangor

Member
Licensed User
Longtime User
OK, sorry to be a pain... for some reason I'm just having trouble with this class.

Is there some documentation?

So each checklist must go on a separate scrollview -- I think I got that part now.

How to best clear a checklist? I'm having trouble with that, although it should be simple. I tried removeallviews but that didn't seem to do it.

Merci Informatix.
 

fdx12345

Active Member
Licensed User
Longtime User
Can not download

I cannot download your checklist program. My computer states it is a multi-file and wants the other file(s).
 

Informatix

Expert
Licensed User
Longtime User
Is there some documentation?

All the documentation is in the code. All functions are explained with their parameters and I tried to do many examples to show these functions in a real context. Almost all functions are used in the examples. For a free product, I can't do more.

How to best clear a checklist? I'm having trouble with that, although it should be simple. I tried removeallviews but that didn't seem to do it.

Removing all views from the ScrollView is a right method. I don't know why that didn't work in your code. The safest method is to re-initialize the class (I mean: calling Initialize to clear everything and reset the list settings).
 

Dave O

Well-Known Member
Licensed User
Longtime User
finding the list item from an embedded button?

Hi there,

I'm trying out your CheckList view to replace the customListView I'm using now in a simple app. Reason: I'd like users to be able to re-order items in the list, and the drag-and-drop function in your Checklist class is just what I was looking for.

I've created a checkList with using AddCustomItem, pretty much like I was doing for the customListView. Each item has 2 labels and a button. All buttons are initialised to use the same click method.

When the user clicks the button, I know which one (via "Sender"). In my old customListView code, I then called GetItemFromView to get the index of the relevant item, and I could continue from there.

However, I'm not sure how to do this with your CheckList class. For a given button being clicked, I need to find the index of the item - something like FindIdFromView or maybe FindPanelContaining(Sender) and then FindIdFromPanel.

Or is there a better way to handle the button click?

Any help much appreciated. Cheers!
 

Informatix

Expert
Licensed User
Longtime User
Hi there,

I'm trying out your CheckList view to replace the customListView I'm using now in a simple app. Reason: I'd like users to be able to re-order items in the list, and the drag-and-drop function in your Checklist class is just what I was looking for.

I've created a checkList with using AddCustomItem, pretty much like I was doing for the customListView. Each item has 2 labels and a button. All buttons are initialised to use the same click method.

When the user clicks the button, I know which one (via "Sender"). In my old customListView code, I then called GetItemFromView to get the index of the relevant item, and I could continue from there.

However, I'm not sure how to do this with your CheckList class. For a given button being clicked, I need to find the index of the item - something like FindIdFromView or maybe FindPanelContaining(Sender) and then FindIdFromPanel.

Or is there a better way to handle the button click?

Any help much appreciated. Cheers!

From CheckListDemo2:
B4X:
Dim pnl As Panel
pnl = lst.FindPanelContaining(Sender)
The ID is in pnl.Tag.
 

Dave O

Well-Known Member
Licensed User
Longtime User
Yes, that's what I ended up doing - putting the ID into the panel's tag when building the list. Looks like it's working fine now, thanks. I remember using the Tag property often as a workaround long ago in my Borland Delphi days.

BTW, while that works, it would still be handy to have a class function to get the ID from the panel (or embedded view), partly as a complement to the FindPanelWithID function, and also for those developers who might already be using the panel tag for another purpose.

A few more suggestions for improving this class (or perhaps the deluxe commercial class you mentioned earlier in this thread):
- a Clear function (very handy, and follows the pattern from listView and customListView)
- When dragging/dropping, make it clearer where the item will be dropped (e.g. either dynamically move the other panels to make room (hard), or highlight the targeted divider (easier?)). The latter method might also benefit from making the dragged panel semi-tranparent during the drag.

But in the meantime, it looks like CheckList is a good upgrade from customListView for my app. Many thanks! :sign0098:
 

Informatix

Expert
Licensed User
Longtime User
Yes, that's what I ended up doing - putting the ID into the panel's tag when building the list. Looks like it's working fine now, thanks. I remember using the Tag property often as a workaround long ago in my Borland Delphi days.

It's not a workaround and you don't have to set this value. It's how the things work in this class, and that's exactly the same thing in CustomListView (GetItemFromView returns the tag property of the panel).

BTW, while that works, it would still be handy to have a class function to get the ID from the panel (or embedded view), partly as a complement to the FindPanelWithID function, and also for those developers who might already be using the panel tag for another purpose.

You can't use the panel tag in this class for your own purpose (and I see no reason to use it). And I think that a method returning the whole panel instead of just one panel property is more convenient. If you want to know the Top property instead of the Tag property, that could prove to be useful. Don't you think ?

A few more suggestions for improving this class (or perhaps the deluxe commercial class you mentioned earlier in this thread):

Sorry but I renounced to any improvement in this class since UltimateListView is out. I will only fix bugs.

For the Clear function, the Initialize function is a better alternative.

Thanks for the interest in my work.
 

barx

Well-Known Member
Licensed User
Longtime User
Hey Informatix, loving your classes.

Just started using this one, not sure if I'm missing something. How can one clear the list in order to re-use it?

Would clearing the original scrollview do the trick with
B4X:
sv.Panel.RemovAllViews

I'm thinking the list will just be re-populated by the class.

Is there some 'clear' function I missing or is it a matter of some thing like

B4X:
for i = 0 to clsChkList.NumberOfItems - 1 
    clsChkList.RemoveItemAt(0) 'I'm assuming to use 0 each time as the item indexes will reduce as I remove items?? is this right
Next

Any info would be great. Just want to make sure I'm using the intended method. Thanks again...
 

barx

Well-Known Member
Licensed User
Longtime User
Sorry about that, missed them 2 bits, read practically every post as well looking for the answer. Cheers
 

syncmaster13

Member
Licensed User
Longtime User
Hi

I have a few questions about listview in general, using this “clsCheckList” class.
1. In all tutorials to populate a listview I’ve read there is always “For i = 0 To 100, next…” etc.function , but How can I populate listview only after a user enter an "edt_b" (in my example)
2. In my example listview is always updated with a newest values. How can I update only a new view , not all of them ?
3. How to save and load this listview from a file ?


Thank You
 

Attachments

  • example.zip
    17.4 KB · Views: 278

Informatix

Expert
Licensed User
Longtime User
Hi

I have a few questions about listview in general, using this “clsCheckList” class.
1. In all tutorials to populate a listview I’ve read there is always “For i = 0 To 100, next…” etc.function , but How can I populate listview only after a user enter an "edt_b" (in my example)
2. In my example listview is always updated with a newest values. How can I update only a new view , not all of them ?
3. How to save and load this listview from a file ?


Thank You

1) Strange question. What does the loop? It adds items with AddItem or AddItemNoChkbx. So you have the answer. Or I didn't understand the question.

2) I guess that you want to update the content of the item displaying a sum. In this case, check if it is created (if not, it must be), then update its content. The item is a panel containing two labels. You get it with:
B4X:
Dim pnl As Panel = svList.Panel.GetView(position of your item)
And you access to the labels with:
B4X:
Dim lbl1 As Label = pnl.GetView(0)
Dim lbl2 As Label = pnl.GetView(1)

3) You have to write yourself the code to load or save the contents. I don't support CSV files because it is a very limited format. I couldn't handle all situations with it. And, IMHO, list data should be saved to a database, not a file.
 

Dave O

Well-Known Member
Licensed User
Longtime User
I use clsChecklist in my "Multi Clicker" app.

I store the actual data in a list, then load that data into UI views (listviews, etc.) as I move from screen to screen.

There's usually only a small # of items in my list, so I just save it to a map file. I save the data in the list, but you could save it from the listview directly if you preferred. (I like to separate the data from the UI where I can.)

I can send you my source code if you like. It's a pretty simple app, so you should be able to see what I'm doing pretty easily.
 

syncmaster13

Member
Licensed User
Longtime User
Thank You for a replay

My 1st question is about “ID As Object” in AddItemNoChkbx.
In tutorials “i” in loops is used as “ID As Object” and since I have no loop I have to replace it with something else. I think this is the reason why after making few calculations “entire” list always display the same data. Can I ask You to change the code in my example so I can see my mistakes ?
(one example can save a thousands words:confused:)
 

Informatix

Expert
Licensed User
Longtime User
Thank You for a replay

My 1st question is about “ID As Object” in AddItemNoChkbx.
In tutorials “i” in loops is used as “ID As Object” and since I have no loop I have to replace it with something else. I think this is the reason why after making few calculations “entire” list always display the same data. Can I ask You to change the code in my example so I can see my mistakes ?
(one example can save a thousands words:confused:)

I'd like to have the time to do an example, but I'm really too busy.

The ID is an unique identifier for each item. If the position of an item may change (e.g. after a sort), the ID does not.
If you create new items and want to be sure to attribute an unique ID, you can use this trick:
ID = number of items + 1
 

Amalkotey

Active Member
Licensed User
Longtime User
New version v1.6:
Now, you can define the color of checked items and the background color (transparent by default).

Hello Informatix,

thank you for this class. Top work. Can you please show me how the background color, can change text color, etc.? Thank you for your help in advance.

best regards
 

Amalkotey

Active Member
Licensed User
Longtime User
You will find two tutorials in the first post of this thread.

Thanks for the info. The colors I have now adapted so as I need them. Now I have the following problem: By default, the checkbox list is set to multi-selection. I need a real single-selection, as with radio buttons, ie, the previous selection is cleared. So I can identify the item that the user wants to take over.

Where can I use that to realize that? Thanks for your help in advance.
 
Top