Italian ListView grafico con due immagini, due Label popolate da un file di testo.

anallie0

Active Member
Licensed User
Longtime User
Nei vari tentativi e grazie al codice originale del grande Klaus (che trovate quà), ho scritto questo semplice codice per creare un ListView grafico che esce dal classico listview poco estetico.
In questo caso utilizzo due immagini come Item con 2 Label che vengono popolate da un file di testo.
Usatelo e modificatelo a vostro piacimento, magari non è perfetto ma è molto veloce e funzionale :)

B4X:
#Region  Project Attributes
    #ApplicationLabel: listviewex
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: true
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

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.
    Dim  panlist As Panel
    Dim scrolllista As ScrollView
    Dim labtitle As Label
    Dim item As Int
 

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("Layout1")
 
    Activity.LoadLayout("main")
 
    panlist.SetLayout(0%x, 0%y, 100%x, 100%y)'with the visible property, managed the panel
    labtitle.SetLayout(0%x, 5%y, 100%x, 10%y)
    scrolllista.Initialize(500)
    panlist.AddView(scrolllista,0%x,16%y,100%x,84%y)

    crealista

End Sub









Sub crealista
    'scrolllista.Panel.RemoveAllViews  ' Write this line if you have many text files and one scrolview. Clear Previous List
    Dim Bitmap1 As Bitmap
    Dim Panel0 As Panel
    Dim PanelTop, PanelHeight  As Int
    Dim lista As List
 
    lista=File.ReadList(File.DirAssets,"listlabel.txt")
 
 
    Bitmap1.Initialize(File.DirAssets,"banner1.png") ' First image of list
    PanelTop=1%y
    Panel0=scrolllista.Panel
    Panel0.Color=Colors.argb(0,0,0,0)  'sets the invisible panel
 
    For i=0 To lista.Size-1
 
        If i>0 AND i<3 Then Bitmap1.Initialize(File.DirAssets,"banner.png")  'Images beyond the first. Only if you use 2 images and 2 label
        Dim ImageView1 As ImageView
        ImageView1.Initialize("View")     
        PanelHeight=12%y
     
        Panel0.AddView(ImageView1,5%x,PanelTop,90%x,PanelHeight)

        ImageView1.Tag=i&"1"
        ImageView1.Bitmap=Bitmap1
        ImageView1.Gravity=Gravity.fill
     
        Dim Label1, Label2 As Label
        Label1.Initialize("")
        Label2.Initialize("")
        Panel0.AddView(Label1,5%x,PanelTop-2%y,90%x,PanelHeight)
        Panel0.AddView(Label2,5%x,PanelTop+2%y,90%x,PanelHeight)
     
        Label1.TextColor= Colors.black
        Label1.TextSize= 17 
        Label1.Gravity=Gravity.CENTER
        Label1.Color=Colors.argb(0,0,0,0)
        Label1.Text=lista.Get(i)

        Label2.TextColor= Colors.black
        Label2.TextSize= 15 
        Label2.Gravity=Gravity.CENTER
        Label2.Color=Colors.argb(0,0,0,0)
        Label2.Text=lista.Get(i+1)
     
        i=i+1 
     
        If i > lista.size-1 Then i = lista.size-1
     
     
        PanelTop=PanelTop+PanelHeight
    Next
    Panel0.Height=PanelTop
 
End Sub 

Sub View_Click
    Dim Send As View
    Dim row As Int
    Send=Sender
 
    row=Floor(Send.Tag/20)
        item=row
 
    labtitle.Text="Item "&item
     
End Sub



Sub Activity_Resume
 

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 

End Sub
 

Attachments

  • list viewex.zip
    109.6 KB · Views: 283
  • Screenshot_2014-05-19-22-05.png
    Screenshot_2014-05-19-22-05.png
    164.8 KB · Views: 345
Last edited:

ivanomonti

Expert
Licensed User
Longtime User
Utile in molti versi grazie del tuo prezioso contributo, questo e spirito di collaborazione e condivisione.
 
Top