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,093
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,347
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,350
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,268
Last edited:

alexposta2

Member
Licensed User
Longtime User
thank you for quick response.

for some strange reason b4a did not save the correct value of the eventname on the designer.
I've resaved all layouts and now work fine.

thank you again
 

PFlores81

Active Member
Licensed User
Longtime User
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 with a very nice tab selector and page indicator like in the new google apps (Market, Google+, etc)

There are three objects in this library:

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.

AHViewPagerTabs - This (optional) object provides a nice tab selector and indicator for the sliding panels. This object is based on the ViewPagerTabs implementation from Andreas Stütz and you can find it here.

For a detailed usage explanation see the example project.

You need at least B4A 1.8. Copy the two jar files and the xml file to your custom libs folder.

You sir, are the man. This is exactly what I was looking for as part of my project. Thank you for sharing!
 

corwin42

Expert
Licensed User
Longtime User
Updated first post with version 1.01 of the AHViewPager library. This version adds the AHViewPagerFixedTabs object. This is a different type of tab indicator with fixed tabs like the normal tabhost object but with a Holo design.

See the first post for a screenshot.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Updated first post with version 1.01 of the AHViewPager library. This version adds the AHViewPagerFixedTabs object. This is a different type of tab indicator with fixed tabs like the normal tabhost object but with a Holo design.

See the first post for a screenshot.

I was looking for this for a while!!!
I even made my own tabs with command buttons. I'll probably use it in my later versions now.
Thanks a lot.
 

gpsoftuk

Member
Licensed User
Longtime User
Is it possible to change the separator color of the FixedTabs? Or remove the separator? Please see the attached image what I mean
 

Attachments

  • Image1.png
    Image1.png
    10.7 KB · Views: 352

PHB2

Member
Licensed User
Longtime User
I'm sorry this is such a newbie question, but since I am trying to get your example working I need to ask it in this thread.

I get this error when compiling this example:

Compiling code. Error
Error parsing program.
Error description: Unknown type: ahpagecontainer
Are you missing a library reference?
Occurred on line: 35
Dim container As AHPageContainer

Where do I need to copy your files to? where exactly is the custom libs folder?
 

Sytek

Active Member
Licensed User
Longtime User
Kawabunga! Amigo :SHOCKED:
Thank you! Thank you Thank you!
I came from VFP9, and suddenly i found this awesome Framework

Best Regards
Sytek
 

aardsoft

Member
Licensed User
Longtime User
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 with a very nice tab selector and page indicator like in the new google apps (Market, Google+, etc)

There are four objects in this library:

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.

AHViewPagerTabs - This (optional) object provides a nice tab selector and indicator for the sliding panels. This object is based on the ViewPagerTabs implementation from Andreas Stütz and you can find it here.

AHViewPagerFixedTabs - This (optional) object provides a nice tab selector with fixed tabs. This object is based on the ViewPagerExtensions library from Andreas Stütz See here
For a detailed usage explanation see the example project.

You need at least B4A 1.8. Copy the two jar files and the xml file to your custom libs folder.

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
Great promise but absolutely useless to a newbie like me. More explanation of how to get this working would be appreciated.
 

salmander

Active Member
Licensed User
Longtime User
Compiling code. 0.01
Compiling layouts code. 0.00
Generating R file. 0.00
Compiling generated Java code. Error
javac 1.6.0_26
src\com\viewpager\com\main.java:206: cannot find symbol
symbol : class ViewPagerWrapper
location: package de.amberhome.viewpager
public de.amberhome.viewpager.ViewPagerWrapper _pager = null;
^
1 error


i have copied the AHViewPager jar and xml files to my Additional Libs folder.
 

salmander

Active Member
Licensed User
Longtime User
Did you check it in the libraries tab?
i am using the sample project attached. The libraries marked are AHViewPager and Core.
I am using B4Av9.2.
I have tried installing jdk1.7 and still having the same error message.
Configure paths are;
C:\Program Files (x86)\Java\jdk1.7.0_03\bin\javac.exe

C:\Android\platforms\android-15\android.jar
 

salmander

Active Member
Licensed User
Longtime User
I've just downloaded the attached project and it compiles fine. It seems like some configuration error with the library.
Thanks Erel,
I have tried using library v1.00 and v1.01, both of them are giving the compiling error. I guess I have to wait for the fix then :(
 

corwin42

Expert
Licensed User
Longtime User
I have just seen that I haven't packed the android-support-v4.jar to the 1.01 archive of the library. It is available in the 1.0 archive. Did you add this jar to your additional libraries folder, too?
 

salmander

Active Member
Licensed User
Longtime User
I have just seen that I haven't packed the android-support-v4.jar to the 1.01 archive of the library. It is available in the 1.0 archive. Did you add this jar to your additional libraries folder, too?
Boom....Its working now...

Thanks a lot mate.
 

raistlin74

Member
Licensed User
Longtime User
Hi all,
I have a strange problem using this library.

I have a for next loop that call a procedure to create the tabs.
If I go with debug step by step, everythings works.
But if I launch the app it gives me error on adding panel.

The code I use to create the panel is :

If iPositionMap < mapCover.Size Then
Dim pan As Panel
strNCover = mapSerie.GetValueAt(iPositionMap)
pan = CreatePanel(cEpisodi.GetString("NOME_EP"))
Log("Pagina : " & iPositionMap)

container.AddPage(pan,"")
pager.Initialize(container, "Pager")
'As we want to show the tabs page indicator, we initialize it
fixedTabs.Initialize(pager)
'fixedTabs.TextSize = 8
'fixedTabs.TextColor = Colors.Cyan
fixedTabs.LineColor = Colors.Black
fixedTabs.LineColorSelected = Colors.White
fixedTabs.LineHeightSelected = 8dip
fixedTabs.LineHeight = 8dip
fixedTabs.Color = Colors.Black
fixedTabs.UpperCaseTitle = True
Activity.AddView(fixedTabs, 0, 0, 100%x, 5dip)

'Now we can add the pager to the activity
' Activity.AddView(pager, 0, 5dip, Activity.Width, Activity.Height-108dip)
Activity.AddView(pager, 0, 5dip, Activity.Width, Activity.Height)
' If mapCover.GetValueAt(iPositionMap) <> "download" Then
iPositionMap = iPositionMap + 1
' End If
End If

And the error is :
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

It creates the first 2 tab and gives error on the third tab.

I am missing something?

Thanks
Fabio
 

corwin42

Expert
Licensed User
Longtime User
Do you use the whole code snippet in your for/next loop?

Then you get the error because you add the fixedTabs and the pager multiple times to the activity.
 
Top