Android Question [Solved] NavDrawer ListViewItem_Click Error

nso91191

Member
Licensed User
Longtime User
Help Me
How To Solve this Problem ...
And Then
i ask one more question :D
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim NavDrawer As AHNavigationDrawer
   'ListView inside Nav Drawer
   Dim LV1 As ListView
   'Panel holds NavDrawer's content
   Dim pContent As Panel
   'Amount to descend when drawer opens
   Dim descendAmount As Int = 20dip
 
End Sub


Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
'   Activity.LoadLayout("Main")
Activity.Title = "Slide out drawer"
   'Initialize the navigation drawer.
   NavDrawer.Initialize("NavDrawer", Activity, 240dip)
 
   'We add the ListView to our NavigationPanel and set it up
   LV1.Initialize("LV1")
   NavDrawer.NavigationPanel.AddView(LV1, 0, 100dip, 100%x, 100%y)
   NavDrawer.NavigationPanel.Color = Colors.ARGB(88,98,98,98)
   LV1.AddSingleLine2("Test", 1)
   'Remove the fade on the background when drawer is open
   SetScrimColor(NavDrawer, Colors.Transparent)
 
   pContent.Initialize("")
   NavDrawer.ContentPanel.AddView(pContent, 0 ,0, 100%x, 100%y)

   pContent.Color = Colors.Green
 
   'Send behind the drawer
   pContent.SendToBack
''   pContent.LoadLayout("") 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SetScrimColor(Nav As AHNavigationDrawer, Color As Int)
  Dim r As Reflector
  r.Target = Nav
  r.Target = r.GetField("mNavDrawer")
  r.RunMethod4("setScrimColor", Array As Object(Color), Array As String("java.lang.int")) 
End Sub

'Animate on sliding the drawer
Sub NavDrawer_DrawerSlide (Position As Float, DrawerGravity As Int)
   Dim Offset As Int = Position * descendAmount
   pContent.Left = Offset
   pContent.top = Offset
   pContent.Width = 100%x - 2 * (Offset)
   pContent.Height = 100%y - 2 * (Offset)
End Sub


Sub LV1_ItemClick ( Item As String, Value As Object, Position As Int)
If Item = 1 Then
MsgBox("Test","What")
Log("Test")
End If
NavDrawer.CloseDrawer
End Sub


java.lang.Exception: Sub lv1_itemclick signature does not match expected signature.


at anywheresoftware.b4a.BA.raiseEvent2(BA.java:177)
at anywheresoftware.b4a.BA$2.run(BA.java:285)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4456)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Sub lv1_itemclick signature does not match expected signature.​
 

DonManfred

Expert
Licensed User
Longtime User
Ummm... The normal click-sub for an Listview looks like
B4X:
Sub lv1_ItemClick (Position As Int, Value As Object)
End Sub
 
Upvote 0

nso91191

Member
Licensed User
Longtime User
B4X:
Sub lv1_ItemClick (Position As Int, Value As Object)
If Value = "Test" Then
Msgbox("Test","What")
Log("fuckfuckfuck")
End If
NavDrawer.CloseDrawer
End Sub

Error Solve Thank @DonManfred

but nothing happen when i click event NavDrawer.CloseDrawer Only Work
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but nothing happen when i click event NavDrawer.CloseDrawer Only Work
please note that the "Value" you may be not the text which is viewed in the listitem...

Without seeing more of your code it is hard to help.

Can you please upload your project (Export as zip) so i can have a deeper look into your problem
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
LV1.AddSingleLine2("Test", 1)
This is your problematic line. Your set the Value 1 here. NOT "Test"

please change it to
B4X:
' Here i create a map with three iteminfos. I store the map in the items value to get it later back in itemclick
Dim retMap As Map = CreateMap("Text":"test","ID":1,"Info":"Info about that item")
LV1.AddSingleLine2(retMap.Get("Text"), retMap)

then change your lv item click sub
B4X:
Sub lv1_ItemClick (Position As Int, Value As Object)
    ' New code
    Dim retMap As Map = Value
    If retMap.Get("Text") = "Test" Then
        Log("huuuuuuuuuuu1342434234")
        For i = 0 To retMap.Size-1
            Log(retMap.GetKeyAt(i)&"="&retMap.GetValueAt(i))
        Next
    End If
   
    ' your old code here...
    If Value = "Test" Then
        Log("huuuuuuuuuuu1342434234")
    End If
NavDrawer.CloseDrawer
End Sub

I have not tried it cause i setup my computer new and i figured that it seems i´m missing the devicedriver in windows.
But it should work
 
Upvote 0

nso91191

Member
Licensed User
Longtime User
Thank Bro
i need help one more


B4X:
Sub lv1_ItemClick (Position As Int, Value As Object)
'This Code Work
NavDrawer.CloseDrawer
If Value = 1 Then
Msgbox ("Hi","")
End If

End Sub

i need webview in pContent Panel show how to do
 
Upvote 0

nso91191

Member
Licensed User
Longtime User
Please Help me one more

how to do visible= false for view

and click first smile<< why get error
 

Attachments

  • Haha.zip
    9.3 KB · Views: 159
Upvote 0

nso91191

Member
Licensed User
Longtime User
lol solve it :D

it's correct code ?

B4X:
#Region  Project Attributes
   #ApplicationLabel: TestDrawer
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim NavDrawer As AHNavigationDrawer
   'ListView inside Nav Drawer
   Dim LV1 As ListView
   'Panel holds NavDrawer's content
   Dim pContent As Panel  
   'Amount to descend when drawer opens
   Dim descendAmount As Int = 20dip
   Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
'   Activity.LoadLayout("Main")
   Activity.Title = "Slide out drawer"
   'Initialize the navigation drawer.
   NavDrawer.Initialize("NavDrawer", Activity, 240dip)
   
   'We add the ListView to our NavigationPanel and set it up
   LV1.Initialize("LV1")
   NavDrawer.NavigationPanel.AddView(LV1, 0, 100dip, 100%x, 100%y)
   NavDrawer.NavigationPanel.Color = Colors.ARGB(88,98,98,98)
   LV1.AddSingleLine2("idiot", 0)
   LV1.AddSingleLine2("happy", 1)
   LV1.AddSingleLine2("smile", 2)
   'Remove the fade on the background when drawer is open
   SetScrimColor(NavDrawer, Colors.Transparent)
   
   pContent.Initialize("pContent")
   NavDrawer.ContentPanel.AddView(pContent, 0 ,0, 100%x, 100%y)
   pContent.Color = Colors.Green

   'Send behind the drawer
   pContent.SendToBack

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SetScrimColor(Nav As AHNavigationDrawer, Color As Int)
  Dim r As Reflector
  r.Target = Nav
  r.Target = r.GetField("mNavDrawer")
  r.RunMethod4("setScrimColor", Array As Object(Color), Array As String("java.lang.int"))   
End Sub

'Animate on sliding the drawer
Sub NavDrawer_DrawerSlide (Position As Float, DrawerGravity As Int)
   Dim Offset As Int = Position * descendAmount
   pContent.Left = Offset
   pContent.Top = Offset
   pContent.Width = 100%x - 2 * (Offset)
   pContent.Height = 100%y - 2 * (Offset)

End Sub

Sub lv1_ItemClick (Position As Int, Value As Object)
NavDrawer.CloseDrawer
 Select Position
       Case 0 : Test1
       Case 1 : Test2
       Case 2 : Test3
End  Select
End Sub

Sub Test1
     WebView1.Initialize("WebView1")
     WebView1.ZoomEnabled = False
     WebView1.LoadUrl("http://www.google.com.mm")
         ProgressDialogShow("Loading ...")
     pContent.AddView(WebView1, 0, 0, 100%x, 100%y)
End Sub

Sub WebView1_PageFinished (Url As String)
   ProgressDialogHide
End Sub

Sub Test2
   RemoveViews
   pContent.LoadLayout("1.bal")
End Sub

Sub Test3
   RemoveViews
   pContent.LoadLayout("2.bal")
   
End Sub


'Correct Code It's work :D
Sub RemoveViews
   Dim i As Int
   
   For i=pContent.NumberOfViews-1 To 0 Step -1
     pContent.RemoveViewAt(i)
   Next
End Sub
 
Upvote 0
Top