[class]custom listview work with loadlayout

icefairy333

Active Member
Licensed User
Longtime User
first see the screen pic:
attachment.php

you can use this like:
B4X:
'Activity module
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 mLv As mylistview
   Dim pp As Panel
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")
   pp.Initialize("pp")
   Activity.AddView(pp,0,0,-1,-1)
   mLv.Initialize(pp)
   Activity.AddMenuItem("clear","clear")
   filldata
   
End Sub
Sub clear_Click
   mLv.ClearItems
End Sub
Sub filldata
Dim lbl1 As Label
   Dim btn As Button
   Dim iv As ImageView
   Dim bmp1,bmp2 As Bitmap
   bmp1.Initialize(File.DirAssets,"1.jpg")
   bmp2.Initialize(File.DirAssets,"2.jpg")
   For i=0 To 39 
      mLv.AddItem("it",60dip)
      'lbl1=mLv.GetItem(i,0)
      lbl1=mLv.GetItem2(i,"lb1")
      lbl1.TextColor=Colors.Red
      'lbl1=mLv.GetItem(i,1)
      lbl1=mLv.GetItem2(i,"lb2")
      lbl1.TextColor=Colors.green
      'btn=mLv.GetItem(i,2)
      btn=mLv.GetItem2(i,"btn")
      btn.Text="按钮"&(i+1)
      'iv=mLv.GetItem(i,3)
      iv=mLv.GetItem2(i,"iv")
      If (i Mod 2=0) Then
         iv.Bitmap=bmp1
      Else
         iv.Bitmap=bmp2
      End If
   Next
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
some code in the class:
B4X:
Public Sub AddItem(layName As String,nItemHeight)
   Dim p As Panel
   p.Initialize("p")
   p.Tag=nCount
   sv.Panel.AddView(p,0,nHeight,-1,nItemHeight)
   p.LoadLayout(layName)
   sv.Panel.Height=nHeight+p.Height
   nHeight=nHeight+p.Height
   nCount=nCount+1
End Sub

in the layout:
attachment.php

you should set the tag,then use it in code like:
B4X:
Dim iv As ImageView
iv=mLv.GetItem2(i,"iv")
 

Attachments

  • pic.jpg
    pic.jpg
    90 KB · Views: 677
  • mylistview_class_demo.zip
    14.7 KB · Views: 310
  • layout.jpg
    layout.jpg
    54 KB · Views: 615

coslad

Well-Known Member
Licensed User
Longtime User
Hi,

great class , in the 2013 i think that the layout must be designed and not written from code ( this is the reason why Visual basic is becomed so famous).
I tried to use the loadlayout with the alternative listview from Erel but without success .

The only missing thing is a separation line between the items.
can you fix it ?

Thanks
 
Top