B4A Library [Class] Expandable Panels

Intro:
These are simple panels that can be easily expanded and collapsed with a small animation.

Future Improvements:
There can be many improvements to this class, and I would love to learn what the best coding style for classes is.
- Coding style (what is exposed and what is not, comments, handling views)

License:
Free to use. But post any modifications, and improvements back here so the community version becomes better.

Better Demo apk: See here

EDIT:
Class improved with better animations with Informatix's NOA library. Sample available in this post: http://www.b4x.com/android/forum/threads/class-expandable-panels.27366/page-2#post-275751
 

Attachments

  • expSample.png
    expSample.png
    30.7 KB · Views: 1,923
  • ExpandablePanelsSample.zip
    7.5 KB · Views: 1,173
Last edited:

Russ

Member
Licensed User
Longtime User
This class is fantastic, thank you. I've made a really neat implementation of it that'll I'll share soon as our app is released.

I have a question though, how do I access a control within an activity that is loaded into the panel, within the expanding panel. Particularly I want to add items to a Spinner that is within the activity from my module.

Thank you
 

Russ

Member
Licensed User
Longtime User
I think I need a better grasp of what a View is, but that looks great, thank you.

I'm adding my expPanel like this

B4X:
    'Create Lights panel
    ExpLightsPanel.Initialize("ExpPnls", "Main")
    LightsPanel = ExpLightsPanel.AsPanel
    ScrollViewHome.Panel.AddView(LightsPanel,10dip,Top,100%x-20dip,LightsHeight)
    LightsPanel.LoadLayout("Lights")
    ExpLightsPanel.setSpeed(5,15)
    ExpLightsPanel.maxHeight = 50dip
    ExpLightsPanel.minHeight = LightsHeight

Within the Lights activity I have a spinner called mySpinner, I'll put the code up once I've figured out how to use GetView :)

The expanders run really slow in Rapid Debug but fine in Release mode, do you have the same? I'm buying another handset with little power (my main is a Note 3) to test my app performance on in Release mode just to be sure :)

Thanks again!
 

Russ

Member
Licensed User
Longtime User
Ok I've figured it out, the first lesson was a "View" is what I would term a control :)

There maybe a more efficient way to do this, but ...

I gave my "View" a tag of SLS.

B4X:
'Hook up controls
    Dim SpinnerLightShow As Spinner
    SpinnerLightShow = FindViewByTag("SLS", LightsPanel)

Then I have a function that loops through all the views in my panel recursively and returns the one with the appropriate tag.

B4X:
Sub FindViewByTag(theTag As String, thePanel As Panel) As View

    For Each v As View In thePanel.GetAllViewsRecursive
        If v.Tag = theTag Then
            Return v
        End If
    Next
   
    Log("Error, func FindViewByTag couldn't find a view with tag "&theTag)
    Return Null
   
End Sub

Thanks again.
 

thedesolatesoul

Expert
Licensed User
Longtime User
You did well, that is how I would do it too. :)

The expanders run really slow in Rapid Debug but fine in Release mode, do you have the same? I'm buying another handset with little power (my main is a Note 3) to test my app performance on in Release mode just to be sure :)

Thanks again!
Yes, sometimes it is slow and not so smooth but it depends on how much work is being done on the background and whether the timers can trigger on the right time.
I did rewrite this class or a similar one (I cant even remember now!), using the NineOldAndroid lib (by Informatix but not avalilable freely) which is an animation lib and the results were much smoother.
 

Russ

Member
Licensed User
Longtime User
Yeah I figured it's just down to timers, I'm doing some basic animation in a different activity using timers and I'm worried it'll behave very differently on each handset :)

The user ratings will tell I guess ...

:)
 

stanks

Active Member
Licensed User
Longtime User
in your sample:
B4X:
Sub expPnls_Resize(MyExpPnl As expandablePanel)
    For i = 0 To pnls.Length-1 -1
        pnls(i+1).Top = pnls(i).Top+pnls(i).Height + 10dip
    Next
    sv.Panel.Height = pnls(pnls.Length-1).Top + pnls(pnls.Length-1).Height
End Sub
if we have 40 panels (0..39) why panels.lenght - 2?
 

joseluis

Active Member
Licensed User
Longtime User
Hi TDS, I' can't make this last version work with your example from the first post. First I had to remove a parameter from expPnls(i).setSpeed(5) in line 50, so it can compile. And then the app fails when clicking in a panel, giving this message:

An error has occurred in sub: java.lang.Exception: Sub exppnls_click signature does not match expected signature. Continue?
 

joseluis

Active Member
Licensed User
Longtime User
Thanks now it works beautifully!! And thanks :) I'm liking so much all the improvements done to b4a during my absence. And this time I plan to finish the apps I started ;)
 

microbox

Active Member
Licensed User
Longtime User
@ thedesolatesoul - thanks for this class. Can you show me how to add image view on each panel?

Edit:
Okay now I got it...thank you again for sharing.
 
Last edited:

little3399

Active Member
Licensed User
Longtime User
Hi, Thedesolatesou

Does this expandpanel class can support how many panels ? TKS , because I using 4 , and
it will be cause error
 

little3399

Active Member
Licensed User
Longtime User
Here is the error message ...
 

Attachments

  • upload_2015-4-28_14-56-37.png
    upload_2015-4-28_14-56-37.png
    115.7 KB · Views: 261
Top