Sub LoadSlideMenu
CLVL.Clear
If Main.gLogin = 0 Then
CLVL.Add(CreateMenu(Chr(0xF090), "Log in"), "Log in")
CLVL.Add(CreateMenu(Chr(0xF234), "Register"), "Register")
Else
CLVL.Add(CreateMenu(Chr(0xF05A), "About Me"), "About Me")
CLVL.Add(CreateMenu(Chr(0xF013), "Change Password"), "Change Password")
CLVL.Add(CreateMenu(Chr(0xF08B), "Log out"), "Log out")
End If
End Sub
Private Sub CreateMenu (MenuIcon As String, MenuText As String) As B4XView
Dim Height As Int = 60dip
Dim Width As Int = CLVL.AsView.Width
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, Width, Height)
p.LoadLayout("MenuItem")
lblMenuIcon.Text = MenuIcon
lblMenuText.Text = MenuText
Return p
End Sub
You just need to apply the same idea to populate the items. When you get the data from jrdc as resultset, use Do While loop to read the values.Thank you very much for your time. Am sorry, this is static drawer population I still desire it to come from jrdc that is, from mysql. Thanks
CREATE TABLE `menus` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`menu` varchar(50) NOT NULL,
`islogin` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `menus` (`id`, `menu`, `islogin`) VALUES
(1, 'Log in', 0),
(2, 'Register', 0),
(3, 'About Me', 1),
(4, 'Change Password', 1),
(5, 'Log out', 1);
sql.getMenus= SELECT menu FROM B4X.menus WHERE islogin = ?
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Drawer.Initialize(Me, "Drawer", Root, 400dip)
Drawer.LeftPanel.LoadLayout("LeftMenu")
LoadSlideMenu(1)
End Sub
Sub CreateRequest As DBRequestManager
Dim req As DBRequestManager
req.Initialize(Me, Main.rdcLink)
Return req
End Sub
Sub CreateCommand (Name As String, Parameters() As Object) As DBCommand
Dim command As DBCommand
command.Initialize
command.Name = Name
If Parameters <> Null Then command.Parameters = Parameters
Return command
End Sub
Private Sub CreateMenu(MenuText As String) As B4XView
Dim Height As Int = 60dip
Dim Width As Int = clvLeftMenu.AsView.Width
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, Width, Height)
p.LoadLayout("MenuItem")
lblMenu.Text = MenuText
Return p
End Sub
Sub LoadSlideMenu (isLogin As Int)
Dim req As DBRequestManager = CreateRequest
Dim com As DBCommand = CreateCommand("getMenus", Array As Object(isLogin))
Wait For (req.ExecuteQuery(com, 0, Null)) JobDone (job As HttpJob)
If job.Success Then
req.HandleJobAsync(job, "req")
Wait For (req) req_Result (res As DBResult)
'req.PrintTable(res)
clvLeftMenu.Clear
For Each row() As Object In res.Rows
clvLeftMenu.Add(CreateMenu(row(0)), row(0))
Next
Else
xui.MsgboxAsync(job.ErrorMessage, "Error")
End If
job.Release
Log("Left Menu populated")
End Sub
Private Sub clvLeftMenu_ItemClick (Index As Int, Value As Object)
Log(Value)
End Sub
Private Sub CreateSideMenu(MenuText As Object) As B4XView
Dim Height As Int = 60dip
Dim Width As Int = clvLeftMenu.AsView.Width
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, Width, Height)
p.LoadLayout("MenuItemm")
lblMenu.Text = MenuText
Return p
End Sub
Sub LoadSlideMenu (isLogin As Int)
clvLeftMenu.Clear
Dim rs As DBResult
' B4XLoadingIndicator1.Show
Dim Paremeters() As String = Array As String(isLogin) ', B4XPages.MainPage.KVS.Get("id_user"))
Wait For(B4XPages.MainPage.jRDC.GetRecord("getMenus", Paremeters)) Complete (Answer As Map)
If Answer.Get("Success") Then
Dim mapData As Map
' Log(Answer)
rs = Answer.Get("Data")
Log(rs)
For Each row() As Object In rs.Rows
' Dim i As Int = 0
mapData.Initialize
' For Each record As Object In row
' 'We will make a map to pass to B4XPreferencesDialo. The map keys must suit to the db name fields
' 'Construimos un mapa para pasarlo a B4XPreferencesDialog. Las claves del mapa deben coincidir con los nombres de las columnas de la bd
' mapData.Put(rs.Columns.GetKeyAt(i), record)
' i = i + 1
' Next
Dim p As B4XView = CreateSideMenu(mapData)
clvLeftMenu.Add(p, mapData)
Log(p)
Next
Else
xui.MsgboxAsync("There was an error getting the data. Check your server: " & Answer.Get("Error"), "Error")
Log("No data")
End If
' Answer.Release
Log("Left Menu populated")
End Sub