Android Question Getting Error while compile CustomlistView

Discussion in 'Android Questions' started by AndroidMadhu, Apr 7, 2019.

  1. AndroidMadhu

    AndroidMadhu 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:
    Code:
    Parsing code.    Error
    Error parsing program.
    Error description: Unknown 
    typejavaobject
    Are you missing a library reference?
    Error occurred on line: 
    88 (CustomListView)
    Dim jsv As JavaObject = sv
    Below is my code
    Code:
    #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
     
  2. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Hello,
    It seems that you just have to include JavaObject from your libraries.
     
  3. AndroidMadhu

    AndroidMadhu Member Licensed User

    Is tat required? If yes, then how to do that
     
  4. lemonisdead

    lemonisdead Well-Known Member Licensed 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.
     
  5. lemonisdead

    lemonisdead Well-Known Member Licensed User

  6. AndroidMadhu

    AndroidMadhu Member Licensed User

    Thanks... it is compiling successfully.
    But another issue I am facing... No text is showing at the customlistview
    For example
    Code:
    Item #1
    Item 
    #2
    Item 
    #3
    ......
    Below is my code
    Code:
    #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
     
  7. AndroidMadhu

    AndroidMadhu 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....
    Code:
    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: Apr 7, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice