Android Question Getting Error while compile CustomlistView

AndroidMadhu

Active Member
Licensed User
Hello,
I am trying to load some simple text in customlistview. I have added the below references
1. XUI
2. StringsUtils
3. Add the module customlistview.bas

I am following the Erel Example and trying to do:
https://www.b4x.com/android/forum/t...-cross-platform-customlistview.84501/#content

But while compiling I am getting the below error and redirecting to customlistview.bas:
B4X:
Parsing code.    Error
Error parsing program.
Error description: Unknown type: javaobject
Are you missing a library reference?
Error occurred on line: 88 (CustomListView)
Dim jsv As JavaObject = sv

Below is my code
B4X:
#Region  Project Attributes
    #ApplicationLabel: CustomListView
    #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.
    Dim xui As XUI
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.
    
    Private CLV1 As CustomListView
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")
    CLV1.DefaultTextBackgroundColor=Colors.Gray
    For i = 0 To 10
        CLV1.Add(createItem("Item #" & i,CLV1.AsView.Width,40dip),i)   
    Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

private Sub createItem(Text As String,width As Int,height As Int) As B4XView
    Dim p As B4XView=xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,100%x,10%x)
    p.Color=Colors.Blue
    
    Return  p
End Sub
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
It seems that you just have to include JavaObject from your libraries.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
As with any other library to include in your project : check the checkbox about JavaObject in the Libraries panel of B4A IDE.
And yes, from the error message, JavaObject is required.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
And yes, from the error message, JavaObject is required.

Thanks... it is compiling successfully.
But another issue I am facing... No text is showing at the customlistview
For example
B4X:
Item #1
Item #2
Item #3
......

Below is my code
B4X:
#Region  Project Attributes
    #ApplicationLabel: CustomListView
    #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.
    Dim xui As XUI
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.
    
    Private CLV1 As CustomListView
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")
    CLV1.DefaultTextBackgroundColor=Colors.Gray
    For i = 0 To 10
        CLV1.Add(createItem("Item #" & i,CLV1.AsView.Width,40dip),i)   
    Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

private Sub createItem(Text As String,width As Int,height As Int) As B4XView
    Dim p As B4XView=xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,100%x,10%x)
    p.Color=Colors.White
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text=Text
    lbl.TextColor=Colors.Black
    p.AddView(lbl,0,0,4dip,5dip)
    
    Return  p
End Sub
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Fixed the issue.... It is problem with height and width of label control.
Now I have created the button dynamically. But not able to control the width and height of the button....
B4X:
Dim btnxpan As Button
btnxpan.Initialize("")
btnxpan.Color=Colors.Gray
btnxpan.TextColor=Colors.Black
btnxpan.Width=30%x
btnxpan.Text=Text
p.AddView(btnxpan,90%x,10dip,10dip,10dip)
Return p
 
Last edited:
Upvote 0
Top