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,349
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,267
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
What happened to 1.02? Did it go the way of the "New" iPad? :D Best Buy had the Galaxy S3 for $100 off about a week and a half ago plus I had a $50 credit making it $50, so I upgraded to it. Funny thing is the old library didn't have the same issue with it as it did my Note. I'll have to test this on my Note (That is now the wife's) when I get home to see if it works too since both work fine on my S3.

So, what exactly needed changing to make it draw correct? I recently started braving the word of JAVA again and started re-writing my main app in Eclipse and it is a totally different world from B4A. XML layouts are great and I love how it is almost like designing them in HTML/CSS...kinda makes me wish I could design them in XML and use them in B4A. The TabHost gave me some issues in B4A running on Honeycomb that I don't see with straight Java, so perhaps whatever was causing the issues with this could be resolved with what you found or a tweak to how Erel creates the Tabhost too.

Once I confirm this working on all my devices I may end up switching gears since the JAVA coding is slow. The main thing missing is a good camera library, so I may try my hand at libraries since it is easier to code in B4A. Thanks for the quick update on this.
 

NilsBe

Member
Licensed User
Longtime User
Start on a different page than 0

this AHViewPager library is really great!

I have only one question or issue regarding the initial view.

I want to use the library in a way that one of the other pages is shown, not the first one.

I took the example and added pager.GotoPage(1,False) at the end of Activity_Create. But after this change, the tabs page indicator at the top does not show properly.

B4X:
Sub Activity_Create(FirstTime As Boolean)

   ....

   pager.GotoPage(1,False)
End Sub

any Idea?

Thanks
Nils
 

corwin42

Expert
Licensed User
Longtime User
See the comment in the example.
B4X:
Sub Activity_Resume
   'Do not call this in Activity_Create since the initialization is not complete then!
   pager.GotoPage(CurrentPage, False)
End Sub

You can not call GotoPage() in Activity_Create since the initialization of the ViewPager is not complete then.
 

NilsBe

Member
Licensed User
Longtime User
See the comment in the example.
B4X:
Sub Activity_Resume
   'Do not call this in Activity_Create since the initialization is not complete then!
   pager.GotoPage(CurrentPage, False)
End Sub

You can not call GotoPage() in Activity_Create since the initialization of the ViewPager is not complete then.

Ok. I tried now something like this:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

   Dim TYPE_HELLO_WORLD As Int : TYPE_HELLO_WORLD = 1
   Dim TYPE_SETTINGS As Int : TYPE_SETTINGS = 2
   Dim TYPE_LISTVIEW As Int : TYPE_LISTVIEW = 3

   Dim FILL_PARENT As Int : FILL_PARENT = -1
   Dim WRAP_CONTENT As Int : WRAP_CONTENT = -2

   'We put this information to the panel tag of the panel for the pages
   Type PanelInfo (PanelType As Int, LayoutLoaded As Boolean) 

   Dim CurrentTheme As Int : CurrentTheme = 0
   Dim CurrentPage As Int : CurrentPage = 1
End Sub

But still not a correct behavior when sliding left and right....
 

corwin42

Expert
Licensed User
Longtime User
AHViewPager1_03.zip? Yes. Can you reproduce the behaviour? Can I do something to show it to you?

I can not reproduce your problem and I don't know exactly what you mean with "still not a correct behavior when sliding left and right". What is not correct?
 

NilsBe

Member
Licensed User
Longtime User
Solved

The problem was solved after I changed from API 8 to API 10.

Everything is fine now.

Thanks to corwin42
 

NilsBe

Member
Licensed User
Longtime User
Not Solved

The problem was solved after I changed from API 8 to API 10.

Everything is fine now.

Thanks to corwin42

Unfortunately I was wrong and the Problem ist not yet solved.

I have created a short screencast as I feel not able to describe the problem properly. Please see the screencast and check the Tabs.

https://docs.google.com/open?id=0ByLJL22HCpymd2RicXFnUXhKMFk

The base for this is the example: AHViewPagerExample1_0.zip with AHViewPager1_03.zip installed.

I had just changed line 27 from

B4X:
   Dim CurrentPage As Int : CurrentPage = 0
to

B4X:
   Dim CurrentPage As Int : CurrentPage = 1

It is compiled with B4A Version 2.22.
The Android Version is 4.1.2 API Level 16.
JDK is: jdk1.7.0_03.

Any other Information which I can provide?

Thx
Nils
 
Last edited:

NilsBe

Member
Licensed User
Longtime User
help!

Unfortunately I was wrong and the Problem ist not yet solved.

I have created a short screencast as I feel not able to describe the problem properly. Please see the screencast and check the Tabs.

https://docs.google.com/open?id=0ByLJL22HCpymd2RicXFnUXhKMFk

The base for this is the example: AHViewPagerExample1_0.zip with AHViewPager1_03.zip installed.

I had just changed line 27 from

B4X:
   Dim CurrentPage As Int : CurrentPage = 0
to

B4X:
   Dim CurrentPage As Int : CurrentPage = 1

It is compiled with B4A Version 2.22.
The Android Version is 4.1.2 API Level 16.
JDK is: jdk1.7.0_03.

Any other Information which I can provide?

Thx
Nils

I have now two different Systems to compile the app. On one it works on one I get the weird behaviour mentioned above.

Which are the different parameters that I can change? First I thought it's the jdk Version. Which I know now is not.

Sorry, I am a little bit confused...
 

corwin42

Expert
Licensed User
Longtime User

NilsBe

Member
Licensed User
Longtime User
I think in Sub Pager_PageChanged is a line to update the tabs ( tabs.NotifyDataChange). Remove this. This should fix the problem.

to which post are you referring?

Are you talking about AHViewPagerExample1_0.zip?
 

corwin42

Expert
Licensed User
Longtime User
to which post are you referring?

Are you talking about AHViewPagerExample1_0.zip?

Yes, and your problem with the tabs not behaving correctly.
 

NilsBe

Member
Licensed User
Longtime User
Yes, and your problem with the tabs not behaving correctly.

Ok. Thanks for your reply, but there is no tabs.NotifyDataChange in Sub Pager_PageChanged in AHViewPagerExample1_0.zip.

only in Sub NewPage_Click and Sub DeletePage_Click.

Nils
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Ok. Thanks for your reply, but there is no tabs.NotifyDataChange in Sub Pager_PageChanged in AHViewPagerExample1_0.zip.

only in Sub NewPage_Click and Sub DeletePage_Click.

Sorry, then I can't reproduce your problem. I had exactly this effect when the tabs were recreated on the PageChanged Event. Perhaps you can post your project?
 
Top