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,074
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,328
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,335
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,240
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
In brief, the parent always obeys to its children. I wasn't aware of that before.
lol...me neither...i guess its modern times!

With the new version, UltimateListView acts now as a good boy and doesn't request anything if you use the added function, so AHViewPager won't miss an event.
My Android knowledge increases every day... thanks to bugs. :)
Indeed. Its a minefield of bugs.
 

corwin42

Expert
Licensed User
Longtime User
Is it worth trying the latest android-support-v4.jar in case something has been fixed in that?

I try to always use the latest support-v4.jar.

If a child requests some touch events for itself, the parent has to ignore these events. It's convenient when you want to disable the scrolling in a list for example, but it's strange to me that there's no possibility to accept or not this behavior.

I think this problem is discussed on StackOverflow in a few questions and there are some other solutions there. But if your change works nicely I will leave my library as it is.

My Android knowledge increases every day... thanks to bugs. :)
Thats the good thing about bugs. :)

Btw: Moved the 2.0 version of the library I posted in the thread some time ago to the first post.
 

GuyBooth

Active Member
Licensed User
Longtime User
With the new version, UltimateListView acts now as a good boy and doesn't request anything if you use the added function, so AHViewPager won't miss an event.
Just trying Ultimate List View on AHViewer with ULV panel width set to -1. The results are very patchy - one swipe it works and sometimes the next swipe it doesn't.
 

GuyBooth

Active Member
Licensed User
Longtime User
I now have ulv and ahviewpager panels working very well together.
Thanks for everyone's help so far!
Is there a way to temporarily "freeze" the ahviewer sideways movement (for instance, have a long click freeze the panel so I can sideways swipe an individual item on a scrollview)?
 

corwin42

Expert
Licensed User
Longtime User
Is there a way to temporarily "freeze" the ahviewer sideways movement (for instance, have a long click freeze the panel so I can sideways swipe an individual item on a scrollview)?

Currently this is not possible. I have found a "hack" on stackoverflow how to do this. Will try it in the next days.
 

JTmartins

Active Member
Licensed User
Longtime User
Some help needed here

Edited...

No way to have bitmaps with fixed tabs, right ?

I think that will make this lib Ultra Perfect !!!

If you have some time, corwin42, pleaaase.

Anyway, I found a not conventional way to do it using background...But it saves the day !!!! - at least with my resolution...but pretty sure it will be distorted with other dip.

Thanks
Jose
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
No way to have bitmaps with fixed tabs, right ?

No, currently no bitmaps. It should be quite easy to manually create fixed tabs for the viewpager. Change the tab with PageChanged event and on click on a tab call the GotoPage Method.

BTW: First post updated with Version 2.01 which adds a "PagingEnabled" property. If set to false paging is not possible anymore. Even the click events on the tabs won't work but you still can change page with the GotoPage method.
 

Smee

Well-Known Member
Licensed User
Longtime User
I guess you didn't copy both jar files to the custom libs dir or you don't use B4A 1.8.

You gave this answer to a previous enquiry

Parsing code. 0.02
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. 0.44
Compiling generated Java code. Error
B4A line: 67
container.Initialize
javac 1.6.0_29
src\de\amberhome\viewpagerexample\main.java:272: cannot access android.support.v4.view.PagerAdapter
class file for android.support.v4.view.PagerAdapter not found
mostCurrent._container.Initialize(mostCurrent.activityBA);
^
1 error

I have the same error. I have made sure both files have been copied to the correct paths. i am using Note2 and B4A V 2.5

Any suggestions?


SORRY !
y Bad. I didnt read the solution properly. it has compiled ok now
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
You gave this answer to a previous enquiry

Parsing code. 0.02
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. 0.44
Compiling generated Java code. Error
B4A line: 67
container.Initialize
javac 1.6.0_29
src\de\amberhome\viewpagerexample\main.java:272: cannot access android.support.v4.view.PagerAdapter
class file for android.support.v4.view.PagerAdapter not found
mostCurrent._container.Initialize(mostCurrent.activityBA);
^
1 error

I have the same error. I have made sure both files have been copied to the correct paths. i am using Note2 and B4A V 2.5

Any suggestions?

If you read carefully the error message, you can see that the problem concerns "android.support.v4". Do you have this library ?
 

tbankuti

New Member
Licensed User
Longtime User
I am experiencing some problem :/

I love the look and the reviews about this library.. but I am having some trouble with it. >> I am a newbie :)

<ccode>
Parsing code. 0.03
Compiling code. 0.08
Compiling layouts code. 0.01
Generating R file. 0.08
Compiling generated Java code. Error
B4A line: 67
container.Initialize
javac 1.6.0_39
src\de\amberhome\viewpagerexample\main.java:276: cannot access android.support.v4.view.PagerAdapter
class file for android.support.v4.view.PagerAdapter not found
mostCurrent._container.Initialize(mostCurrent.activityBA);
^
1 error
</ccode>

####

Thx corwin42!
You've answered my question :).
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
I love the look and the reviews about this library.. but I am having some trouble with it. >> I am a newbie :)

<ccode>
Parsing code. 0.03
Compiling code. 0.08
Compiling layouts code. 0.01
Generating R file. 0.08
Compiling generated Java code. Error
B4A line: 67
container.Initialize
javac 1.6.0_39
src\de\amberhome\viewpagerexample\main.java:276: cannot access android.support.v4.view.PagerAdapter
class file for android.support.v4.view.PagerAdapter not found
mostCurrent._container.Initialize(mostCurrent.activityBA);
^
1 error
</ccode>

Did you read the post just before yours ?
 
Top