first see the screen pic:
you can use this like:
some code in the class:
in the layout:
you should set the tag,then use it in code like:
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
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:
you should set the tag,then use it in code like:
B4X:
Dim iv As ImageView
iv=mLv.GetItem2(i,"iv")