B4A Library jfeinstein10 SlidingMenu library

Erel

Administrator
Staff member
Licensed User
The open source project is no longer maintained and there are compatibility issues with newer versions of Android. It is recommended to use B4XDrawer instead.

This is a wrapper for jfeinstein10 SlidingMenu open source project. This is a popular implementation of sliding menus. Note that you can add any layout you like in each of the side menus.

upload_2014-1-7_16-43-16.png

upload_2014-1-7_16-43-2.png

It requires B4A v6+

Example code:
B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim sm As SlidingMenu
End Sub

Sub Activity_Create(FirstTime As Boolean)
   sm.Initialize("sm")
   Dim offset As Int = 100dip
   sm.BehindOffset = offset
   sm.Mode = sm.BOTH
   Dim lv1 As ListView
   lv1.Initialize("lv1")
   For i = 1 To 10
     lv1.AddSingleLine("Action "  & i)
   Next
   sm.SecondaryMenu.AddView(lv1, 0, 0, 100%x - offset, 100%y)
   Dim b1, b2 As Button
   b1.Initialize("b1")
   b2.Initialize("b2")
   b1.Text = "Button1"
   b2.Text = "Button2"
   sm.Menu.AddView(b1, 10dip, 10dip, 100%x - offset - 20dip, 50dip)
   sm.Menu.AddView(b2, 10dip, 60dip, 100%x - offset - 20dip, 50dip)
End Sub
Sub lv1_ItemClick (Position As Int, Value As Object)
   Log(Value)
   sm.HideMenus
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK AND sm.Visible Then
     sm.HideMenus
     Return True
   End If
   Return False
End Sub
Sub B1_Click
   Log("b1_click")
   sm.HideMenus
End Sub
Sub B2_Click
   Log("b2 click")
   sm.HideMenus
End Sub
 

Attachments

Last edited:

Theera

Well-Known Member
Licensed User
Hi all,
From my picture,How to match correct folder in using #AdditionalRes module attribute to reference this project res folder and package? Is right?

B4X:
#AdditionalRes: #AdditionalRes: C:\Users\ธีระ\Desktop\New Folder (2)\SlidingMenu-master\library\src\com\jeremyfeinstein\slidingmenu\lib , com.jeremyfeinstein.slidingmenu.lib, com.jeremyfeinstein.slidingmenu.lib
 

Attachments

M6SOFT

Member
Licensed User
Hi,
When I add second #AdditionalRes (google-play-services_lib\res, com.google.android.gms) in the demo program at first post i have an error when try to compile:

B4X:
SlidingMenu\library\res\values\ids.xml:3: error: Resource at selected_view appears in overlay but not in the base package; use <add-resource> to add.
Is there any solution to mix google maps and jfeinstein10 SlidingMenu library?

Best Regards
greg
 

Erel

Administrator
Staff member
Licensed User
This is a bug that will be fixed in the next version.

For now you need to copy the resources of both projects to each other. The google map res folder should be identical to this library res folder.
 

M6SOFT

Member
Licensed User
Hi Erel,
Thanks for reply.
After copy res folders i have 2 identical with duplicated all files. Then it cause:
Generating R file. Error
C:\android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\ads_attrs.xml:10: error: Attribute "adSize" has already been defined
C:\android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\ads_attrs.xml:13: error: Attribute "adUnitId" has already been defined
C:\android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\attrs.xml:20: error: Attribute "mode" has already been defined
.....
I will be waiting for new version.
Thanks
greg
 

tchart

Active Member
Licensed User
Erel, I downloaded the Sliding Menu Demo from the Play Store (ie http://bit.ly/TWejze). One of the demo menus has options to change the look and feel of the sliding menus (shadow, transition effect etc). However I cant see these properties in the wrapper. Are they not implemented yet?
 

Erel

Administrator
Staff member
Licensed User
Not all the API is currently exposed. It should be quite simple to access most of the API that is not exposed with JavaObject.
 

Roger C

Active Member
Licensed User
I don't get it, which folder should I refer to in the Project Attributes?
In the file from GitHub there's a library-folder with an almost empty folder named '\res', it contains two folder and nothing else...

The pic shows how the files look like in Windows Explorer.

And this is what I refer to:
B4X:
#Region  Project Attributes
    #ApplicationLabel: Dagbok
    #VersionCode: 241
    #VersionName: 2.4.1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: True
    #AdditionalRes: C:\AndroidApps\DagbokVit\SlidingMenu\library\res, com.jeremyfeinstein.slidingmenu.lib
#End Region
Still it complains that it's an unreferenced library and the code is red...
What files should be in the 'res'-folder? even if I point it to the \example\res folder, nothing happens...
 

Attachments

Erel

Administrator
Staff member
Licensed User
You should also add a reference to SlidingMenuWrapper library in the libraries tab.
 

Roger C

Active Member
Licensed User
Haha, yes of course. In bed last night I came up with that too. :) I was so focused about adding the resource. First timer...
Works like a charm, very nice. :)
 

Erel

Administrator
Staff member
Licensed User
Try this:
B4X:
Dim jo As JavaObject = SlidingMenu1
jo.RunMethod("setTouchmodeMarginThreshold", Array(50%x))
 

Douglas Farias

Expert
Licensed User
Try this:
Code:
Dim jo As JavaObject = SlidingMenu1
jo.RunMethod("setTouchmodeMarginThreshold", Array(50%x))
this works fine 40000% best *-*

here is the code if help someone
B4X:
#Region  Project Attributes
  #ApplicationLabel: B4A Example
  #VersionCode: 1
  #VersionName:
  'SupportedOrientations possible values: unspecified, landscape or portrait.
  #SupportedOrientations: unspecified
  #CanInstallToExternalStorage: False
  #AdditionalRes: C:\Users\Douglas\Documents\SlidingMenu-master\library\res, com.jeremyfeinstein.slidingmenu.lib
#End Region

#Region  Activity Attributes
  #FullScreen: False
  #IncludeTitle: True
#End Region

Sub Process_Globals
End Sub

Sub Globals
  Dim sm As SlidingMenu
End Sub

Sub Activity_Create(FirstTime As Boolean)
  sm.Initialize("sm")
  Dim offset As Int = 200dip
  sm.BehindOffset = offset
  sm.Mode = sm.LEFT
 
  Dim jo As JavaObject = sm
    jo.RunMethod("setTouchmodeMarginThreshold", Array(50%x))

  Dim lv1 As ListView
  lv1.Initialize("lv1")
  For i = 1 To 10
    lv1.AddSingleLine("Action "  & i)
  Next
  sm.SecondaryMenu.AddView(lv1, 0, 0, 100%x - offset, 100%y)
  Dim b1, b2 As Button
  b1.Initialize("b1")
  b2.Initialize("b2")
  b1.Text = "Button1"
  b2.Text = "Button2"
  sm.Menu.AddView(b1, 10dip, 10dip, 100%x - offset - 20dip, 50dip)
  sm.Menu.AddView(b2, 10dip, 60dip, 100%x - offset - 20dip, 50dip)
End Sub
Sub lv1_ItemClick (Position As Int, Value As Object)
  Log(Value)
  sm.HideMenus
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK AND sm.Visible Then
    sm.HideMenus
    Return True
  End If
  Return False
End Sub
Sub B1_Click
  Log("b1_click")
  sm.HideMenus
End Sub
Sub B2_Click
  Log("b2 click")
  sm.HideMenus
End Sub
 

Johnmcenroy

Active Member
Licensed User
I have an error: inconvertible types using the following code:
B4X:
sm.Menu.AddView(smScroll,10dip, 10dip, 200dip, 100%y)
smScroll is CustomListView

Update
Solved
It must be:
B4X:
sm.Menu.AddView(smScroll.AsView,10dip, 10dip, 200dip, 100%y)
Thanks
John
 
Last edited:
Top