B4J Tutorial Customized ListView

alienhunter

Active Member
Licensed User
Longtime User
hi
i try to understand why the background is still white in bj4.jpg
but the fx.jpg is set to black and ( i am loading it with LoadLayout )
do i have to specify the css for it ?
"ListView1.StyleClasses"


thanks AH


B4X:
For i = 0 To 100
        Dim p As AnchorPane
        p.Initialize("")
        p.LoadLayout("ListItem")
        ImageView1.SetImage(backbmp)
      
        listview1.Items.Add(p)
      
Next
 

Attachments

  • fx.jpg
    fx.jpg
    16.2 KB · Views: 2,254
  • bj4.jpg
    bj4.jpg
    147.5 KB · Views: 2,840

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I downloaded ImageDownloader, opened and ran it in B4J. When I click on Designer, Listitem.fxml, and Edit layout, IE opens the xml file. Where is the Scene Builder? How do I install it?

Any help will be appreciated.

Edit - found problem:
I reassigned the extension fxml to open with Scene Builder instead of IE. Thanks anyway.
 
Last edited:

B4JExplorer

Active Member
Licensed User
Longtime User
How do you add Strings, which are retrieved from the Text property of a TextField, to a ListView? Append/Add doesn't do the trick.
 
Last edited:

B4JExplorer

Active Member
Licensed User
Longtime User
How do you handle a Mouse DOUBLE click event? Need to be able to double click a ListView item, resulting in the copying of the item text, back into a Textbox, where it originally came from.

Also, any way of responding to ENTER on a listview item? I know _Action is appropriate for other controls, but anything analogous on a listview?
 
Last edited:

B4JExplorer

Active Member
Licensed User
Longtime User
See the example in the first post. You can add labels and set their EventName parameter (it is an empty string in the above example). This will allow you to handle the labels MouseClicked event.

The EventData parameter holds the number of clicks.

Good, thanks Erel.
 

adalexander

Member
Licensed User
Longtime User
B4J ListView can hold simple items like strings or numbers and also customized items.
The core ListView is similar to both B4A ListView and CustomListView class.

Adding custom items is done by adding Nodes to the ListView items collections.
Instead of showing the item "value" the Node itself will be displayed.
The Node can be an AnchorPane that holds other nodes or it can be any other node type as well.

For example to create a list that shows the available fonts:

SS-2013-11-25_10.14.46.png


B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private lv As ListView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   lv.Initialize("lv")
   MainForm.RootPane.AddNode(lv, 0, 0, 0, 0)
   MainForm.RootPane.SetAnchors(lv, 0, 0, 0,0)
   For Each family As String In fx.GetAllFontFamilies
     Dim lbl As Label
     lbl.Initialize("")
     lbl.Text = family
     lbl.Font = fx.CreateFont(family, 22, False, False)
     lv.Items.Add(lbl)
   Next
End Sub

Sub lv_SelectedIndexChanged(Index As Int)
   If Index > -1 Then
     Dim lbl As Label = lv.SelectedItem
     Log(lbl.Text)
   End If
End Sub

A more complicated example is attached. It uses ImageDownloader to download a list of images (similar to this B4A example: http://www.b4x.com/android/forum/th...ple-way-to-download-images.30875/#post-179512 )

Note that the images show when they are ready.

SS-2013-11-25_10.43.44.png


This feature depends on v1.00 (beta 5+).
Hello erel, we say that a nose I managed to make a listview with bitmaps, now I make sure that references to the touch line starts a call to the number that is written on this list, hog s early activated the library on phone and declared globals : dim p as phnecalls, how can I do to make sure that the call is made? I have seen several guides but none that explains, in addition to this I have another doubt when you turn the smartphone, how can I do so that the app is effectively the same? thanks for everything!
so far no one has responded, I hope you ...
 

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi Erel ,
Could you please tell me what's wrong is in my code ? when i click on list item to get the label content i receive the following error. The error comes from this line Dim lbl As Label = lv.SelectedItem
View attachment 28252
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private lv As ListView
    Dim lbl1 As Label
    Dim chk1 As CheckBox
    Dim p As AnchorPane
    Private Toast As ToastMessageShow

End Sub

Sub AppStart (Form1 As Form, Args() As String)
      MainForm = Form1
   MainForm.Show
   MainForm.RootPane.LoadLayout("Main")
   Toast.Initialize("Toast")

End Sub
Sub fillList
For i=0 To 10
       p.Initialize("")
     p.LoadLayout("listItemP")
     lv.Items.Add(p)
     lbl1.Text = "Test"&"  "&i
     chk1.Checked=False
   Next
End Sub
Sub btnSend_MouseClicked (EventData As MouseEvent)
    lv.Items.Clear
     fillList
End Sub
Sub lv_SelectedIndexChanged(Index As Int)
   If Index > -1 Then
     Dim lbl As Label = lv.SelectedItem
     'Toast.ToastShow(lbl.text)
     Log(lbl.Text)
   End If
End Sub
 

Attachments

  • upload_2014-10-11_15-17-37.png
    upload_2014-10-11_15-17-37.png
    36.4 KB · Views: 856
Top