Android Question CustomListView.SV.SetBorderAndColor

Elric

Well-Known Member
Licensed User
Hi everybody!

After having searched and tried I haven't find a solution.

My aim is to change the border color (at run time) to a CustomListView. Not to single item o to single panel but to the entire CustomListView.

In B4J this is not an issue. This code
B4X:
clv.sv.SetColorAndBorder(xui.Color_DarkGray, 5dip, xui.Color_Green, 5dip)
works perfectly.

In B4A the border disappear at the level of each item (it seems "sent to back").

I've tried checking both XUI Views library and xCustomListView library (I've not well understood why "CustomListView" view is available also with only XUI View but I'll open another thread for this).

Thanks!
 

mangojack

Well-Known Member
Licensed User
Longtime User
One solution ... place the CLV on a Pane/Panel B4XView , and set the color & border to that view.
 
Upvote 0

Elric

Well-Known Member
Licensed User
Thank you @mangojack !

Your solution is immediate but I should insert a Pane/Panel for each of my four clv and to write different code for B4J and B4A. Not a such big issue, in fact, but if I may manage it with less views and less code rows should be better for me.

I'll use your solution in the case working onto clv will not be possible.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
and to write different code for B4J and B4A.

Why different code ?
You have Panes in B4J layout and Panels in B4A layout with the same Name ... but generate / declare them as B4xView

In both platforms , same code
B4X:
myPaneOrPanel.SetColorAndBorder(xui.Color_White, 5dip, xui.Color_Blue, 5dip)

Edit ... there is no drama using Dip in B4J bye the way .
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
In B4A the border disappear at the level of each item (it seems "sent to back").
Here is an example that will set the border and background for each item at run time:
B4X:
For Each s As String In MyList
            Dim pnl As B4XView = xui.CreatePanel("") 
            pnl.SetLayoutAnimated(0, 0,0, clv1.AsView.Width, 85dip)     
            pnl.LoadLayout("Item")  'layout has 1 label: LblText
            pnl.SetColorAndBorder(xui.Color_DarkGray, 5dip, xui.Color_Green, 5dip)      'THIS IS YOUR NEW LINE    
            LblText.Text = s
            clv1.Add(pnl, s)
    Next
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
@Mahares ... 😉
My aim is to change the border color (at run time) to a CustomListView. Not to single item o to single panel but to the entire CustomListView.
 
Upvote 0

Elric

Well-Known Member
Licensed User
My CustomListView has a fixed height and variable text.

If the text length takes less space than the height of the CustomListView there is no problem: with the ResizeItem function I can set the item with an height equal to CustomListView height. In this case, the item border coincide (more or less) with the CustomListView border.

In the case the text length takes more space than the height of the CustomListView, the item becomes scrollable, the height of the single item will be higher than the height of the CustomListView and the two border will not coincide.
1652891020571.png


The solution suggested by @mangojack has the problem that if the panel is brought in front of the CustomListView, the item will no more be scrollable; if it is sent back then it is not visible. The solution is to make the pane/panel a little more bigger than the CustomListView: not the best for me.
 
Upvote 0

Elric

Well-Known Member
Licensed User
You are right.

Here a little project (just clv without pane/panel).

Three changes at clv-click:
- borders
- TextSize
- text bold

The behaviors in B4A and in B4J is little different. In particular, the bold font in B4J works only if the sub ResetAll run before.

Thank you.
 

Attachments

  • CLVBorederTextSizeAndBold.zip
    17.1 KB · Views: 99
Last edited:
Upvote 0

Elric

Well-Known Member
Licensed User
Starting from mangojack solution, a workaround could be resizing the clv when the panel appear:
B4X:
    Private clv as CustomListView
    Private pnl asB4X
    clv = (...)
    pnl = (...)
    clv.AsView.Top = pnl.Top + 5dip
    clv.AsView.Height = pnl.Height - 10dip
    clv.AsView.Left = pnl.Left + 5dip
    clv.AsView.Width = pnl.Width - 10dip
    If clv.GetPanel(0).Height < clv.AsView.Height Then
        clv.ResizeItem(clv.Size - 1, clv.AsView.Height - 8)
    End If

and resize again when the panel disappear
B4X:
    Private clv as CustomListView
    Private pnl asB4X
    clv = (...)
    pnl = (...)
    clv.AsView.Top = pnl.Top
    clv.AsView.Height = pnl.Height
    clv.AsView.Left = pnl.Left
    clv.AsView.Width = pnl.Width
    If clv.GetPanel(0).Height < clv.AsView.Height Then
        clv.ResizeItem(clv.Size - 1, clv.AsView.Height - 8)
    End If
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Starting from mangojack solution, a workaround could be resizing the clv when the panel appear:

My "solution" was based on my impression you had a single CLV with some items .. and suggested the CLV was added TO a Panel , enabling a border to be displayed.

So I'm slightly lost now what you are trying to do at the moment.

Hopefully @Mahares or @klaus can help.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I made quite some tests with a specific test project to understand what is behind the scene.
I am afraid that you cannot easily do what you want in B4A with an xCustomListView.
The behavior of a B4A ScrollView is different from a ScrollPane in B4J, xCustomListView is based on those
And the structure of the xCustomListView is also more complex with its different layers.

My suggestion is to use for each item a Panel / Pane for the background and EditText / TextArea for the text.
The EditText / TextArea views scroll the text automatically when the text height becomes higher than the view, so no need to adjust any height.

Attached my B4A test project, it is easy to adapt it to B4J.
It contains for comparison:
1 ScrollView as ScrollView
1 ScrollView as B4XView
1 xCustomListView
1 Panel / EditText combination, the EditText has a None text input type.
And a Button to change the text and colors.
The Panel / EditText combination could also be made as a CustomView.
 

Attachments

  • B4AScrollViewBorder.zip
    11.4 KB · Views: 91
Upvote 0

Elric

Well-Known Member
Licensed User
Thanks everybody!

My "solution" was based on my impression you had a single CLV with some items .. and suggested the CLV was added TO a Panel , enabling a border to be displayed.
You're right.

This simple thing (adding clv TO a panel) arrived later in my mind, being concentrated on the border... so, the first think was set visibility of a panel with the border already set instead of use the panel in the appropriate way. Then: instead to keep easy, I took complicated way.
 
Upvote 0
Top