B4J Question ListView in B4J

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

I am attempting to port a [delete B4J] B4A application to B4J. Below is the sub that brings up a LIstView from which a file is selected. I am at a loss as to how I treat the line:
"Activity.AddView(ImportFileView, 0, 10%y, 100%x, 90%y)".

Any help appreciated.


B4X:
Sub FileSelect
'Brings up ListView to allow selection of files.
'Called by BtnFiles_click
    Dim temp As String

    ImportFileView.Initialize("ImportFileView")
     Activity.AddView(ImportFileView, 0, 10%y, 100%x, 90%y)

    'Set the parameters for displaying the Items of the ListView

    FileLabel = ImportFileView.SingleLineLayout.Label

'FileLabel.TextColor = Colors.White
FileLabel.Style = FileLabel.Styl&"-fx-text-fill: White;"

    FileLabel.TextSize = DispInput.TextSize            '14*btnscale

'FileLabel.Color = Colors.DarkGray    
FileLabel.Style = FileLabel.Styl&"-fx-background-color: DarkGray;"
        
    FileLabel.Height = 5%y                                         'Label height and Item Height should match to avoid gsps & overlaps
    ImportFileView.SingleLineLayout.ItemHeight = ImportFileView.SingleLineLayout.Label.Height

'ImportFileView.Color = Colors.DarkGray                        'ListView color matches Label color
ImportFileView.Style = ImportFileView.Styl&"-fx-background-color: DarkGray;"

    ImportFileView.Clear                                        'Clear Listview before populating
    For FileN = 0 To FileListing1.Size-1                        'Builds the viewable list ImportFileView from the List "FileListing"
        temp = FileListing1.Get(FileN)                            'Get the value from the List
        ImportFileView.AddSingleLine(temp)                        'Store the value in the ListView
    Next
    lblTitle.Text = "Select File"
    lblTitle.BringToFront
    lblTitle.Height = 10%y
    lblTitle.width = 100%x
    lblTitle.Top = 0
    ListBack.BringToFront
    ListBack.Height = 10%y
    ListBack.Top = 0
    ListFlag = 1
End Sub


Regards Roger
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
You're attempting to port a B4J app to B4J? Sounds like your work is already done.

In B4J, if you're going to add "Views" (called Nodes) to an "Activity" (called Forms) in code (as opposed to with the Visual Designer), you want to get the Form's RootPane and then add the Node to that. Instead of 100%x, you can get the parent Node's width and multiply that by the desired proportion. I think you'll find B4J easier to design for if you use Anchors, as well.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Thanks Roycefer.

Sorry about the B4J to B4J.
You have given me a lot in a small paragraph. I will chew it over and digest slowly. I will also go back and look at the B4A code and look at each part to see why I have done it that way.

Can you point me to any examples of B4J Listview in use? Reverse engineering is a good way to learn. [IE Dismantling your bicycle when aged 12]

Regards Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Many thanks Roycefer.

I had looked at the tutorial earlier but couldn't make sense of it. With what you have written in #2, looking at the tutorial again things clicked.
I think the barrier is down and I will start working through it.

Thanks Roger.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…