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,110
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,364
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,364
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,284
Last edited:

raistlin74

Member
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.

Thanks for the reply.

But I get the error on the line :

container.AddPage(pan,"")

And in debug mode I don't get the error.
 

derez

Expert
Licensed User
Longtime User
Markus

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?

Thanks for this library. Please update the files in ver 1.01.
It took me a while to find this post in page 8, after banging all four walls around me :)
 

greydog

Member
Licensed User
Longtime User
Hi there,
I have been using this with ListViews and have now changed to ScrollViews in the container. I am fairly new at B4A, but working my way through it. The problem I have is saving the contents on a screen rotate, had it working fine for listviews, but can't seem to crack Scrollviews. Does anyone have a code snippet of how to do this, I would love to use StateManager for my app, but unfortunately doesn't seem to work with AHViewPager so have to do it all manually. Any help gratefully appreciated as I don't have much hair to start with and it is going rapidly ATM.
 

sigster

Active Member
Licensed User
Longtime User
Hi

How can I change Title later like with Button
from "Main" to "list"

B4X:
Container.AddPageAt(Pan(0), "Main", 0)

Regards
Sigster
 

Penfound

Active Member
Licensed User
Longtime User
Does anyone know what number refere to what PANELTYPE I'm looking for one with a WebView?

Cheers
Penfound
 

sorex

Expert
Licensed User
Longtime User
Corwin,

Is there a benefit for using the library instead of the simular module/.bas file?
 

corwin42

Expert
Licensed User
Longtime User
Yes, you have the fixed and the swipey tabs in the library, it is much easier to use and I think you will get strange effects if you try to use Scrollviews or Listviews on a panel in the code module version. Additionally the look and feel (scroll speed etc.) is somehow a standard as many apps use the viewpager.
 

Mahares

Expert
Licensed User
Longtime User
@Markus:
The new fixedtab feature has the best of both worlds: Tabhost and sliding panels in one package. In Tabhost, the tab indicator can have text and a bitmap. How can I implement that to the AHviewPager. In other words, can you have a bitmap along with the page name at the top?
Thank you for a great enhancement.
 

slydog43

Member
Licensed User
Longtime User
I'm getting an error when compiling with 2.x, I assume that is my problem as I think it was created for 1.8. Is there an update to this library?

Nevermind, I found that 1 file from 1.0 was needed and was not included in 1.01.
 
Last edited:

SpaceCow

Member
Licensed User
Longtime User
Hi,

The slider works perfect but i'm getting a error on:
B4X:
container.AddPage(pan,d.name)

I'm adding the pages from a loop and the first and second time when i call the function it works but after that i'm getting the message:
"The specified child already had a parent. You must call removeView() on the child's parent first."

I saw this post but i don't know how to fix it...
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.

Currently this is my code:
B4X:
Sub ShowSchema
   Dim in As InputStream
   Dim col As ColorDrawable
   
   'Layout
   P_LayoutContent.LoadLayout("SchemaLayout")
   
   parser.Initialize
   container.Initialize
   MyDays.Initialize
   in = File.OpenInput(File.DirInternal, "scheme0.dat")
   parser.Parse(in, "SchemaParser")
   in.Close      
   
   'Read list
   For i = 0 To MyDays.Size - 1
      Dim d As Day
      d = MyDays.Get(i)

      'Tabs
      Dim pan As Panel
      pan = CreatePanel(TYPE_LISTVIEW, d.name, d.Activities)
      container.AddPage(pan,d.name)
   Next    
   
   'Now we have a container with our panels just add it to the pager object
   pager.Initialize(container, "Pager")
   
   'As we want to show the tabs page indicator, we initialize it
   tabs.Initialize(pager)
   tabs.LineHeight = 5dip
   tabs.UpperCaseTitle = True
   P_SchemaContent.AddView(tabs, 0, 0, FILL_PARENT, WRAP_CONTENT)
   
   'We add a line below the tab page indicator because it looks good
   col.Initialize(tabs.LineColorCenter, 0)
   line.Initialize("")
   line.Background=col
   P_SchemaContent.AddView(line, 0, 35dip, P_SchemaContent.Width, 2dip)
   
   'Now we can add the pager to the activity
   P_SchemaContent.AddView(pager, 0, 35dip + 2dip, P_SchemaContent.Width, P_SchemaContent.Height-48dip-35dip-2dip)

   'Thema
   tabs.Color = Colors.Black
   tabs.BackgroundColorPressed = Colors.Blue
   tabs.LineColorCenter = Colors.Green
   tabs.TextColor = Colors.LightGray
   tabs.TextColorCenter = Colors.Green
   line.Color = Colors.Green
End Sub

The Sub ShowSchema is called when i select a menuitem from my app.

Can someone help me? Thanks!
 
Top