Android Question CustomListView Background Color

rQb

Member
Licensed User
Hi

Cant locate where I can set the background color of a CLV if panels dont fill out the total area of the CLV. Currently its white but want it to match activity (black).

Thanks in advance

BR
 

eurojam

Well-Known Member
Licensed User
CustomListView is a class based on a Scrollview where you can set the background. You can extent the class with a backgroundcolor, for example put this sub to the class CustomListView
B4X:
Public Sub BackgroundColor(c As Int)
  Dim aP As Panel
  aP = sv.Panel
  aP.Color = c
End Sub
then you will have the possibility to set the background in your activity code like:
B4X:
...
clv1.BackgroundColor(Colors.Red)
...
stefan
 

Prosg

Active Member
Licensed User
I do this who work fine :

I want a background white so i did in Public Sub Initialize

B4X:
 sv.Color = Colors.White
and i add some code in ublic Sub InsertAt

B4X:
Dim sd As StateListDrawable
    sd.Initialize
    sd.AddState(sd.State_Pressed, pressedDrawable)
    sd.AddCatchAllState(Pnl.Background)

    'create another panel to handle the click event
    Dim p As Panel
    p.Initialize("panel")
    p.Background = sd
    Dim cd As ColorDrawable
    cd.Initialize(Colors.Transparent, 0)
    Pnl.Background = cd
    p.AddView(Pnl, 0, 0, sv.Width, ItemHeight)
    p.Tag = Index



    If Index = items.Size Then
        items.Add(Value)
        panels.Add(p)
        Dim top As Int
        If Index = 0 Then top = dividerHeight Else top = sv.Panel.Height
        sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
    Else
        Dim top As Int
        If Index = 0 Then
            top = dividerHeight
        Else
            Dim previousPanel As Panel
            previousPanel = panels.Get(Index - 1)
            top = previousPanel.top + previousPanel.Height + dividerHeight
        End If

        Dim p2 As Panel
        For i = Index To panels.Size - 1
            p2 = panels.Get(i)
            p2.top = p2.top + ItemHeight + dividerHeight
            p2.Tag = i + 1
        Next
        items.InsertAt(Index, Value)
        panels.InsertAt(Index, p)
        sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
    
    End If

        'prosg Add gray divider
        Dim lblDivider As Label
        lblDivider.Initialize("")
        lblDivider.Color = Colors.RGB(247,247,247)
        p.AddView(lblDivider, 0,p.Height-1dip, 100%x, 1dip)

    sv.Panel.Height = sv.Panel.Height + ItemHeight + dividerHeight
    If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + dividerHeight
End Sub
regards
 

Anser

Well-Known Member
Licensed User
I have a CustomListView with its height defined as 100%y. Depending on the available data, the CustomListView may contain many panels and if the data is less then the CustomListView will contain only one or two panels and this may not fill the entire screen length.

Unfortunately, if the CustomListView does not contain enough panels then the background appears to be grey color.

A screen snapshot of what I am trying to explain.
Screenshot.png



My Activity's Background color is white. I did not see any property in Designer also to get this done.

What is the best way to fill the background color of CustomListView with any color that the programmer wish to show and that doesn't effect the divider color ?

The code posted by the user Prosg is working

After adding the code by Prosg the following line in the Activity does the work
B4X:
clv.AsView.Color = Colors.White
I prefer not to modify the Original Class.

Is this the expected behavior OR am I missing something ? Any help will be appreciated.
 
Last edited:
Top