B4A Library AHViewPager library - Sliding panels now perfect

This library is a B4A implementation of the ViewPager object provided by the compatibility class from google. With this library it is possible to add sliding panels to your apps.

AHPageContainer - This object is a container for the pages of the AHViewPager. You should add Panels to this object.

AHViewPager - This is the main object which provides the sliding panels.

All the Tabs objects are deprecated now. You can use them but I don't enhance them anymore. For nice looking Tabs please use the DSTabLayout object of the DesignSupport library.
Alternatively you can use the TabStripViewPager.


Installation:
  • From V3.00 on the library requires B4A 6.0 or later.
  • This library depends on the Android Support library so you need to install the Android Support repository in the Extras section with SDK Manager.
  • Copy the AHViewPager.xml and AHViewPager.jar files to your additional libraries folder.
Example project:

For an example project for this library see the Design Support Library.

Your support:
Creating libraries and wrappers for existing library projects is a lot of work. The use of this library is totally free and you even don't need to mention in your app that you use it.
But if you use this library in your projects and you think it is useful to you please consider to make a donation:

Thanks very much for your support.

Version History:

1.00:
- initial version

1.01:
- Added AHViewPagerFixedTabs object for a fixed tab indicator
- Fixed a bug that it was impossible to get the canvas of a panel which was added to the container (It was impossible to display charts on a page)
- Example for AHViewPagerFixedTabs tab indicator

1.02: (Never released)
- Fixes problem with tab height (Line is now always on the bottom)

1.03:
- Fixes problem with Line sometimes not updating correctly on Android 4.0+
- Fix UppercaseTitle property

2.0:
- Complete Rewrite of the Swipey tabs code to fix some bugs with newer android versions.

2.01:
- New property for the AHViewPager object: PagingEnabled - Enables or disables paging for the ViewPager.

2.02:
- New events PageScrolled and PageScrollStateChanged (with SCROLLSTATE constants)
See post 227 for details

2.20:
- Use raiseEventfromUI() in most events
- New SupportTabs object
- New SupportTitles object
- Support for Designer (as a Custom View)
- some minor internal changes and bug fixes

2.21:
- Use raiseEvent() for PageCreated and PageDestroyed event again to prevent double UI refreshes
- Added @RaiseSynchronousEvents annotation to GotoPage() (to make it better compatible with rapid debugger.

3.00:
- Support for Designer Custom Properties.
- Uses maven repository to access support library. (B4A 6.0 or later required)

Attention: V2.20 has an API change which makes the ViewPager incompatible with older versions. The AHPageContainer parameter is removed from the Initialize() method. Initialize2() has the old signature. If you use Initialize() (or add the View to the Designer as a custom view) then you have to set the container object with ViewPager.PageContainer = <YourContainer>

The examples use the old Initialize method, so they are broken. I was too lazy to fix them because I recommend the tab indicator from the Design Support library for a nice looking Material Design app.
 

Attachments

  • screenshot-1336034831196.png
    screenshot-1336034831196.png
    10.1 KB · Views: 8,103
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,355
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,358
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,278
Last edited:

zeuspower

Member
Licensed User
Longtime User
HELLO!

I have 5 pages for sliding...

they work perfect...what i want is to the 5th page to add an extra Panel so I can use as a target to draw a bars chart (using the charts.bas code)

how i do it ? my pages are something like these:

B4X:
Dim Pan(5) As Panel
            
            Pan(0).Initialize("")
            Pan(1).Initialize("")
            Pan(2).Initialize("")
            Pan(3).Initialize("")
            Pan(4).Initialize("")
            
            
            'Initialize the panels we use for the pages and put them in the container
      Container.Initialize
            
            Pan(0).LoadLayout("Main")
            Container.AddPageAt(Pan(0), "ΕΠΙΛΟΓΗ ΑΣΚΗΣΗΣ", 0)
            
            Pan(1).LoadLayout("Main2")
            Container.AddPageAt(Pan(1), "ΚΑΤΑΧΩΡΗΣΗ", 1)
            
            Pan(2).LoadLayout("Main3")
            Container.AddPageAt(Pan(2), "ΤΡΟΠΟΣ ΕΚΤΕΛΕΣΗΣ", 2)
            
            Pan(3).LoadLayout("Main4")
            Container.AddPageAt(Pan(3), "ΛΙΣΤΑ ΑΣΚΗΣΕΩΣ",3)
            
            Pan(4).LoadLayout("Main5")    <<<<< THIS IS THE PAGE TO ADD A PANEL FOR BARCHART TARGET  ON IT

            Container.AddPageAt(Pan(4), "ΓΡΑΦΗΜΑ ΑΣΚΗΣΗΣ", 4)
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Just noticed: The bug also appears if you delete any page other than page 0. Or any page that becomes the first page after deleting page 0.

Attached you find a new version (2.0) of this library. The code for the ViewPagerTabs is heavily changed and hopefully works correct now. Please be sure to use the latest android-support-v4 library.

With my tests everything works fine now. Can you all please check this and if it works for you I will update the first post.
 

Attachments

  • AHViewPager2_0.zip
    31.5 KB · Views: 237

airblaster

Active Member
Licensed User
Longtime User
I can confirm that the tabs bug is fixed.
Thank you very much for fixing the tabs bug!

Btw, the viewpager bug still exists.
I just set up an emulator with Android 4.0.3, the bug also appears in the emulator.
 

corwin42

Expert
Licensed User
Longtime User
I can confirm that the tabs bug is fixed.
Thank you very much for fixing the tabs bug!

Btw, the viewpager bug still exists.
I just set up an emulator with Android 4.0.3, the bug also appears in the emulator.

Do you refer to the listview event not firing problem?
 

zolive33

Active Member
Licensed User
Longtime User
Hello,

I think there is a little bug with android 4.1.2:

If I use DoEvents in event PageChanged, application crashes when I slide (tested with Android 4.1.2). it works correctly with Android 2.x.

I use AHViewPager v2.0

Have you a solution?

Sorry for my poor english (I'm French).

Regards.
 

corwin42

Expert
Licensed User
Longtime User
Hello,

I think there is a little bug with android 4.1.2:

If I use DoEvents in event PageChanged, application crashes when I slide (tested with Android 4.1.2). it works correctly with Android 2.x.

I use AHViewPager v2.0

Have you a solution?

Sorry for my poor english (I'm French).

Regards.

Don't know what exactly causes this. The library just sets up an OnPageChangeListener for the ViewPager and uses a simple ba.raiseEvent() method to raise the event.

The error is:

B4X:
Fatal signal 11 (SIGSEGV) at 0x45130d91 (code=2), thread 10403 (iewpagerexample)

Perhaps Erel has a clue what happens here?

Just avoid DoEvents in this event sub.
 

zolive33

Active Member
Licensed User
Longtime User
I am looking for a workaround. Perhaps with a timer. I'll let you know ASAP.
 

zolive33

Active Member
Licensed User
Longtime User
I am looking for a workaround. Perhaps with a timer. I'll let you know ASAP.

Here is my solution (tested with Android 2.2 and 4.1.2) :

B4X:
Sub Globals
   
   Dim ViewPager As AHViewPager
   Dim tmWaitingSlide As Timer
   [...]

End Sub

Sub Activity_Create(FirstTime As Boolean)

   tmWaitingSlide.Initialize ("tmWaitingSlide", 500)
   tmWaitingSlide.Enabled = False
   [...]

End sub

Sub ViewPager_PageChanged (Position As Int)
   
   tmWaitingSlide.Enabled = True
   
End Sub

Sub tmWaitingSlide_Tick
   
   tmWaitingSlide.Enabled = False
   
   DoEvents 'usefull for viewing a loader (for example)
   [...]
   
End Sub
 
Last edited:

javiers

Active Member
Licensed User
Longtime User
Hello,
I wanted to create a table in one of the tab using the class [Class] TableView - Supports tables of any size.

Is it possible? If it were, I'd appreciate an example ...

Thanks
 

cstangor

Member
Licensed User
Longtime User
Reinitialize AHPager

How do I remove all of the pages to start over? I noticed that initializing the Class module doesn't do it.

Thanks for the great code.
 

sultan87

Active Member
Licensed User
Longtime User
Merci
mais ne peut pas installer android-support-v4.jar avec
Android SDK Manager Extras Android Support Library
j'ai le message d'erreur

Preparing to install archives
Downloading Android Support Library, revision 11
URL not found: C:\Program Files\Android\temp\support_r11.zip (Accès refusé)
Done. Nothing was installed.

Pourquoi ?

j'ai installé Android 2.2 (api 8)

Cordialement
pierre chevalier
 

sultan87

Active Member
Licensed User
Longtime User
Merci
je lis l'anglais mais j'ai du mal à l'écrire
je regarde sur le site français
Cordialement
Pierre Chevalier
 

erfan

Member
Licensed User
Longtime User
dear corwin42, what you did is awesome and very smooth
but it needs some updates:
1- there is no option of typeface for tabs and titles(changing the font)
2- when i change the text of tabs to something else other than english, there is no line for the selected one. as another user mentioned here and some other posts
 

GuyBooth

Active Member
Licensed User
Longtime User
My AHView panels are sticky

I have four panels.
The first is loaded with a small number (< 100) of items in a custom listview
The second contains a Custom Listview with 900+ items
The third contains a Listview with approx 6000 items
The fourth contains an empty panel.

When I move between Panels 1 and 2 and 2 and 3, I have no problems. I can go back and forth and everything is smooth.
If I then go from panel 3 to panel 4 the movement is smooth. I can now go back and forth between panels 3 and 4 smoothly.

But now, when I go back from panel 3 to panel 2 there is a significant delay - about 2 seconds - before teh panels slides over.
Once at panel 2, I can once again move smoothly back and forth between panels 1, 2 and 3.
If I go back to panel 4 the behaviour repeats itself.

This happens on my Galaxy S3 running Jellybean. It does NOT show up in the simulator! In the simulator it is smooth all the way across all four panels.

Any ideas?
 
Top