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:

android6dft

New Member
Licensed User
Longtime User
Not sure if this has been done before but I've put together a combination of AHViewPage with AHActionBar into a single demo.

Thanks for that. I need a help in adding Scroll to these pages when I fill them with text and images using Label extras. Can you please combine Scroll view to the AHViewPage + AHActionBar .

AHViewPage + AHActionBar + Label Extras + ScrollView.

Thanks
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Two questions:

1. How can I re-init the pages in the entire set when I want to update their contents? By looping over them and deleting them one by one? Or is there a "refresh" function available?
2. Is it safe to add 1000 panels at once? Or should I create my own mechanism by destroying and adding panels on the fly, as you "flick" through the entire set?
 

corwin42

Expert
Licensed User
Longtime User
Two questions:

1. How can I re-init the pages in the entire set when I want to update their contents? By looping over them and deleting them one by one? Or is there a "refresh" function available?
2. Is it safe to add 1000 panels at once? Or should I create my own mechanism by destroying and adding panels on the fly, as you "flick" through the entire set?

1. You can delete alle pages from the pagecontainer or just dim a new one and initialize the ViewPager again with it.
2. Never tried to add that amount of pages but I think it should work. But you should only create the content of a page in the PageCreated event and eventually free any resources in the pagedestroyed event.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Have you got an example on how to create content in the PageCreated event and destroy that in the PageDestroyed event? The example that comes with ahviewpager adds panels on the start of the activity, not in PageCreated or PageDestroyed.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Have you got an example on how to create content in the PageCreated event and destroy that in the PageDestroyed event? The example that comes with ahviewpager adds panels on the start of the activity, not in PageCreated or PageDestroyed.

Is it enough to put pan.Initialize("") in the PageDestroyed event to destroy the contents, or is there something else I should do?
 

corwin42

Expert
Licensed User
Longtime User
Is it enough to put pan.Initialize("") in the PageDestroyed event to destroy the contents, or is there something else I should do?
It depends on what objects you have on your page and you have to make sure that you don't hold any other references to these objects.
 

selvamurali

Active Member
Licensed User
Longtime User
Hi tried the example but i got the error

i have copied bothe jar and xml files to additional libraries folder .

i attach the screenshot of my error
 

Attachments

  • ahpageviewrpblm.png
    ahpageviewrpblm.png
    53.3 KB · Views: 193

AbbasMohammed

Member
Licensed User
Longtime User
Dears,
Kindly, i am wondering how to remove single item (like Label or Image, or button) from one page which is Contained in AHViewPager.
B.R
Abbas
 

wimpie3

Well-Known Member
Licensed User
Longtime User
How can I force the visible page to be updated? I want PageCreated to be called again to refresh the contents of the current page.
 

corwin42

Expert
Licensed User
Longtime User
How can I force the visible page to be updated? I want PageCreated to be called again to refresh the contents of the current page.

The PageCreated event is not the right place to update the variable content of the page. It is the place to create the layout for the page and not the data.
 

AbbasMohammed

Member
Licensed User
Longtime User
Again:
Kindly, i am wondering how to remove single item (like Label or Image, or button) from one page which is Contained in AHViewPager.
B.R
Abbas
 

corwin42

Expert
Licensed User
Longtime User
Again:
Kindly, i am wondering how to remove single item (like Label or Image, or button) from one page which is Contained in AHViewPager.
B.R
Abbas

If you have a referece to the object you want to remove just call its RemoveView method.

You can get the panel you added to the page container with AHPageContainer.GetPageObject(page).
Then you can loop over the objects on this panel and delete the one you want.
 

JForge

Member
Licensed User
Longtime User
Is it possible to use one designer layout for say 7 panels, and have each display different data.

So is it possible to create one designer view with a listview, and then let each sliding panel put different data in its listview?
 

corwin42

Expert
Licensed User
Longtime User
Is it possible to use one designer layout for say 7 panels, and have each display different data.

So is it possible to create one designer view with a listview, and then let each sliding panel put different data in its listview?

Yes of course this is possible and it can be done in several ways.

If you load a layout and you have global variables for the views defined, these variables are filled with the references to the views in the just loaded layout. So you can define the normal global variables for your views and also you can define global arrays for the views. When you now load a layout you can copy the references to the views from the global variables to the array. With the array you will always have access to your views on every page.

This is just one method for doing this. Another would be to add tags to your views in the layout. When you want to modify the value of a view on one page just get the Container Panel from the AHPageContainer and then loop over its views and search for the tag.
 

dealsmonkey

Active Member
Licensed User
Longtime User
I have just created an app for a client using this brilliant library ! It generates a questionaire for a mobile worker to fill in on site and then send back to the office.

The questionnaire is built from a csv file and the page panels and questions are then generated in code. I used an array of panels to identify the panel on which page, ie Panel(0) = page 0, panel(1) = page 1 etc...

I then just added the views to each panel(). I assigned a unique value to each view tag so I could iterate through every view on every page and get the tag value and the user input value. These were then put in a map and finally written back to a CSV for upload back to HQ !

This library works flawless and because it can detect what page a user is on, makes it easy to respond to this, eg. auto save on every 5th page etc

One questionnaire contains 233 questions spread over 33 pages, each question having a mix of a label, radiobuttons and autocomplete editbox. This questionnaire loads complete in approx 6 secs on a Nexus 7 (Old Model!)


I'll post some screenshots if anyone is interested.
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Hello, please can you tell me how disable a page in a panel, to set pag(0).enabled to false.

Thanks

Raffaele
 
Top