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,254
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Hello, Informatix,

I think that I can not see an elephant!

I used your great class adding items using AddCustomItem, which needs the parameter pnlHeight. ALL IT'S OK.

Right now I'm using the command easier AddItem.
It seems to me that, in this case, I am "forced" to calculate the height of the inner panel of ScrollView "host" (I tried to use ResizePanel but the inner panel.height remains 0).
Now I get the right height, but the panel is empty.

I am attaching the project: show me the elephant, please :D

Many thanks.

(I added a method to your class - RemoveAllItems - because I could not find a similar one)
 

Attachments

  • LM_FileManager.zip
    22.8 KB · Views: 232

elbelli2013

Member
Licensed User
Longtime User
Hi,
I make a List2 from List2=lst.CheckedList()

Then I've List2 with all element cheked.

Now I need auto check element in another ClsCheckList using List2.

Anybody Can Help me?


thanks in advance.
 

LucaMs

Expert
Licensed User
Longtime User


I like to help and get a "Thanks", even without "alot", without a "Like" and completely free of charge, of course.

So, Sytek, you can find many of my answers to help, on site, none of these ... short as that!
 

Informatix

Expert
Licensed User
Longtime User
Hi,
I make a List2 from List2=lst.CheckedList()

Then I've List2 with all element cheked.

Now I need auto check element in another ClsCheckList using List2.

Anybody Can Help me?

thanks in advance.
You browse all items of your list in a loop and you set the checked state of each corresponding item in your second ClsCheckList. There's no function to do that automatically.
If you have no idea of how to change the state of a checkbox, you can see the code of the CheckAllBoxes function of the class.
 

elbelli2013

Member
Licensed User
Longtime User
Hello, Informatix, I added a extra function into your class.



Public Sub GetSecondText(ID As Object) As String
Dim pnl As Panel
Log(sv.Panel.NumberOfViews)


For i = 0 To sv.Panel.NumberOfViews-1
pnl = sv.Panel.GetView(i)

If pnl.Tag = Null Then Continue
If pnl.Tag = ID Then
For p = 0 To pnl.NumberOfViews
If IsLabel(pnl.GetView(p)) Then

Log(pnl.GetView(p))
Log(pnl.GetView(p+1))
Log(pnl.GetView(p+2))
' Dim lbl As Label
Dim lbl1 As Label
' lbl = pnl.GetView(p)
lbl1 = pnl.GetView(p+1)
Return lbl1.Text
End If
Next
Exit
End If
Next
Return ""
End Sub




regards.
 

Sytek

Active Member
Licensed User
Longtime User
I like to help and get a "Thanks", even without "alot", without a "Like" and completely free of charge, of course.

So, Sytek, you can find many of my answers to help, on site, none of these ... short as that!

That was for Informatix, not for you
 

Binary01

Active Member
Licensed User
Longtime User
Hi, Infomatix

This post is long time but is amazing and useful for me. I want to know that
how to get item position that user clicked in checklist?
can I change the color of item that user clicked in checklist?

Thanks
 

maleche

Active Member
Licensed User
Longtime User
I read through the blog and might have missed it.
I would like to build a "DropDown" object using a ListView and Spinner.
When selecting the Category "Dog", I would like a dropdown (Spinner?) to show the subcategories from which to choose.
I have made a quick drawing example of what I need.
Any code direction is greatly appreciated!
See attached photo.

Thanks in advanced!
 

Attachments

  • DropDown.png
    DropDown.png
    53.5 KB · Views: 245

LucaMs

Expert
Licensed User
Longtime User
I read through the blog and might have missed it.
I would like to build a "DropDown" object using a ListView and Spinner.
When selecting the Category "Dog", I would like a dropdown (Spinner?) to show the subcategories from which to choose.
I have made a quick drawing example of what I need.
Any code direction is greatly appreciated!
See attached photo.

Thanks in advanced!


Your design is better than mine (probably :D).

I demand even more, here.

But I have seen in the examples that something like this is already part of the class.

upload_2014-8-11_21-15-45.png
 
Last edited:

Touch

Active Member
Licensed User
Longtime User
Hi Informatix,
How can I get the values entered in a EditText?
 
Last edited:

hookshy

Well-Known Member
Licensed User
Longtime User
Any idea how to change the orange color that is describing the press action of items ?
Hope I made myself understood !

I did played with colors found as process variables with no luck.
Thank you
 
Top