Android Question update customlistview

fanfalveto

Active Member
Licensed User
Longtime User
in an customlistview i have 3 imageview an 4 labels with text,in one label i have the hour,minutes and seconds,i need update this label for countdown,countdown not is the problem,the problem is update only this label into customlistview.i try some things but no.
Any idea?
thanks
 

mangojack

Expert
Licensed User
Longtime User
Try this ..

B4X:
'this row/panel has 3 ImageViews(0,1,2)  and 4 Labels (3,4,5,6)
    Dim pnl As Panel
    pnl = CLV1.GetPanel(clickedRow)

    Dim Label1,Label2,Label3,Label4 As Label   
    Label1 = pnl.GetView(3)
    Label1.Text = "This Time"
    Label2 = pnl.GetView(4)
    Label2.Text = "That Time"
    Label3 = pnl.GetView(5)
    Label3.Text = "ABCD"   
    Label4 = pnl.GetView(6)
    Label4.Text = 123456

Cheers mj
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
sorry i don´t understand, i try whit a timer and update into the timer the label,this is the code[QUOTE
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
p.Initialize("")
p.Color = Colors.Transparent
p.SendToBack

reloj.Initialize("")
reloj.Gravity = Gravity.LEFT
hora=DateTime.GetHour(DateTime.Now)
minuto=DateTime.GetMinute(DateTime.Now)
segundo=DateTime.GetSecond(DateTime.Now)
reloj.Text = hora&":"&minuto&":"&segundo
reloj.TextSize = 20
reloj.TextColor = Colors.Red
p.AddView(reloj, 55%x,30%y, 17%x,6%y) 'view #0
tiempo3.Enabled=True

Return p

End Sub
[/QUOTE]
and[QUOTE
Sub tiempo3_Tick
If i=10 Then
i=1
End If
segundo=segundo-1
If segundo=0 Then
minuto=minuto-1
segundo=60
End If
If minuto<0 Then
hora=hora-1
minuto=59
End If

reloj.Text = hora&":"&minuto&":"&segundo
End Sub
][/QUOTE]
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
You should re-create the list item containing the time rather than trying to update the existing item.

Look at the code sample contained here

I think that the code relating to clv2 is what you are trying to do.

Your timer event handler should consist of .RemoveAt(Index) and then CreateListItem.
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
thank you tunderin.
yes i try to removeat(index) on index is the label with the hour,minutes an seconds,but no works.
and i try to change color of button when is pressed (into a panel in customlistview),i can show toastmessageshow when press button but no change color.
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
Can you post your code?
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
yes,[QUOTE
#Region Project Attributes
#ApplicationLabel: pruebapresta
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim tiempo As Timer
Dim tiempo2 As Timer
Dim tiempo3 As Timer
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 b As Button
Dim Button1 As Button
Dim EditText1 As EditText


Dim Label1 As Label
Dim Label10 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Label5 As Label
Dim Label6 As Label
Dim Label7 As Label
Dim Label8 As Label
Dim Panel3 As Panel
Dim Label9 As Label
Dim Panel1 As Panel
' Dim Panel2 As Panel
Dim ImageView1 As ImageView

Dim n As Int=0

Dim clv As CustomListView

Dim p As Panel
Dim i As Int
Dim reloj As Label

Dim hora As Int
Dim minuto As Int
Dim segundo As Int

Dim TimeFont As Typeface
Dim TimeFont1 As Typeface
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("ofertas")
clv.Initialize(Me, "clv")


Activity.AddView(clv.AsView, 2%x, 18%y, 96%x, 81%y)
'ListView1.Initialize("ListView1")
'Spinner1.SetBackgroundImage(LoadBitmap(File.DirAssets,("aa.jpg")))
'spinner1.Color=colors.Cyan
tiempo.Initialize("tiempo",2)
tiempo2.Initialize("tiempo2",2)
tiempo3.Initialize("tiempo3",1000)
ImageView1.Top=0
ImageView1.Left=0
ImageView1.Height=15%y
ImageView1.Width=43%x

Panel1.Height=17%y
Panel1.Width=100%x
'Panel2.Height=80%y
'Panel2.Width=100%x
Panel3.Left=0
Panel3.Top=17%y
Panel3.BringToFront

For i = 1 To 10
clv.Add(CreateListItem("descripcion #" & i, 11%x, 11%y), 45%y, "Item #" & i)
Next
End Sub
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
TimeFont1 = Typeface.LoadFromAssets("gotic.ttf")
p.Initialize("")
p.Color = Colors.Transparent
p.SendToBack

Dim fotoprod As ImageView
fotoprod.Initialize("fotoprod")
fotoprod.SetBackgroundImage(LoadBitmap(File.DirAssets,(i&".jpg")))
fotoprod.Gravity=Gravity.FILL
p.AddView(fotoprod, 2%x,1%y, 50%x,35%y) 'view #1

Dim flecha As ImageView
flecha.Initialize("flecha")
flecha.SetBackgroundImage(LoadBitmap(File.DirAssets,("flecharoja.png")))
flecha.Gravity=Gravity.FILL
p.AddView(flecha, 53%x,20%y, 12%x,7%y) 'view #1

Dim desc As Label
desc.Initialize("")
desc.Typeface = TimeFont1
desc.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
desc.Text = (20+i) & "%"
desc.TextSize = 12
desc.TextColor = Colors.White
p.AddView(desc, 55%x,20%y, 12%x,7%y) 'view #0

Dim precio As Label
precio.Initialize("")
precio.Typeface = TimeFont1
precio.Gravity = Gravity.LEFT
precio.Text = (20+i*i*9) & "€"
precio.TextSize = 12
precio.TextColor = Colors.Black
p.AddView(precio, 66%x,21.5%y, 15%x,7%y) 'view #0

Dim preciodescuento As Label
preciodescuento.Initialize("")
preciodescuento.Typeface = TimeFont1
preciodescuento.Gravity = Gravity.LEFT
preciodescuento.Text = ((20+i*i*9)/2) & "€"
preciodescuento.TextSize = 18
preciodescuento.TextColor = Colors.Red
p.AddView(preciodescuento, 77%x,20.5%y, 215%x,7%y) 'view #0

TimeFont = Typeface.LoadFromAssets("digi.ttf")
reloj.Initialize("")
reloj.Typeface = TimeFont
reloj.Gravity = Gravity.LEFT
hora=DateTime.GetHour(DateTime.Now)
minuto=DateTime.GetMinute(DateTime.Now)
segundo=DateTime.GetSecond(DateTime.Now)
reloj.TextSize = 17
reloj.TextColor = Colors.Red
reloj.Text = hora&":"&minuto&":"&segundo
p.AddView(reloj, 52%x,30%y, 20%x,6%y) 'view #0
tiempo3.Enabled=True

Dim borde As ImageView
borde.Initialize("borde")
borde.SetBackgroundImage(LoadBitmap(File.DirAssets,("borde.png")))
borde.Gravity=Gravity.FILL
p.AddView(borde, 1%x,37%y,94%x,0.2%y) 'view #1

Dim borde2 As ImageView
borde2.Initialize("borde2")
borde2.SetBackgroundImage(LoadBitmap(File.DirAssets,("borde2.png")))
borde2.Gravity=Gravity.FILL
p.AddView(borde2, 0%x,43%y,100%x,4%y) 'view #1

b.Initialize("b") 'all buttons click events will be handled with Sub Button_Click
b.Color=Colors.Red
b.TextColor=Colors.White
b.Typeface = TimeFont1
b.Text="VER"
b.Gravity=Gravity.CENTER_HORIZONTAL
b.Enabled=True
b.Visible=True
b.Text = "VER"
b.TextSize=12
p.AddView(b, 75%x,28%y, 20%x,7%y) 'view #1

Dim txtprod As Label
txtprod.Initialize("")
txtprod.Typeface = TimeFont1
txtprod.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
txtprod.Text = Text
txtprod.TextSize = 16
txtprod.TextColor = Colors.Black
p.AddView(txtprod, 57%x,5%y, 25%x, 5%y) 'view #0

' Dim logo As ImageView
' Dim nombreemp As Label
' Dim sector As Label
Return p

End Sub

Sub b_Click
b.Color=Colors.Black
b.TextColor=Colors.White
p.RemoveAllViews
ToastMessageShow("ok", False)
End Sub

Sub clv_ItemClick (Index As Int, Value As Object)
Activity.Title = Value &" "&Index
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

End Sub

Sub Label10_Click
Panel3.Width=100%x
Label10.TextColor=Colors.White
tiempo.Enabled=True
End Sub
Sub tiempo_Tick
n=n+10
Panel3.Visible=True
Panel3.Enabled=True
If n<291 Then
Panel3.Height=n
Else
tiempo.Enabled=False
End If
'Log (n)
End Sub
Sub tiempo2_Tick
n=n-10
'Log("tiempo "&n)
'Panel3.Visible=True
'Panel3.Enabled=True
If n>-1 Then
Panel3.Height=n
Else
tiempo2.Enabled=False
End If
End Sub
Sub tiempo3_Tick
If i=10 Then
i=1
End If
segundo=segundo-1
If segundo=0 Then
minuto=minuto-1
segundo=60
End If
If minuto<0 Then
hora=hora-1
minuto=59
End If
hora=DateTime.GetHour(DateTime.Now)
minuto=DateTime.GetMinute(DateTime.Now)
segundo=DateTime.GetSecond(DateTime.Now)
' reloj=p.GetView(10)
reloj.Text = hora&":"&minuto&":"&segundo

' Log(reloj.Text)
'Log(hora&":"&minuto&":"&segundo)
End Sub
][/QUOTE]
and thak you for tour help
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
Could you post your code as a zip?

Also, code is easier to read if you use the code tags (the button to the left of what you are using).
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
I find a solution thanks,maybe not the best but works
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
TimeFont1 = Typeface.LoadFromAssets("gotic.ttf")
p.Initialize("")
    p.Color = Colors.Transparent
p.SendToBack
Dim texto(9) As String=Array As String ("en","es","us","al","pi","po","na","ne","pi","jo")
Dim descrip(10) As Label
descrip(ii-1).Initialize("")
descrip(ii-1).Typeface = TimeFont1
    descrip(ii-1).Gravity = Bit.OR(Gravity.TOP, Gravity.LEFT)
    descrip(ii-1).Text =texto(ii-1)
    descrip(ii-1).TextSize = 12
    descrip(ii-1).TextColor = Colors.Black
    p.AddView(descrip(ii-1), 55%x,1%y, 37%x,20%y) 'view #0
i=i+1

    Dim fotoprod As ImageView
    fotoprod.Initialize("fotoprod")
fotoprod.SetBackgroundImage(LoadBitmap(File.DirAssets,(i&".jpg")))
            fotoprod.Gravity=Gravity.FILL
            p.AddView(fotoprod,  2%x,1%y, 50%x,35%y) 'view #1
           
Dim flecha As ImageView
flecha.Initialize("flecha")
flecha.SetBackgroundImage(LoadBitmap(File.DirAssets,("flecharoja.png")))
            flecha.Gravity=Gravity.FILL
            p.AddView(flecha,  53%x,20%y, 12%x,7%y) 'view #2

Dim desc As Label
desc.Initialize("")
desc.Typeface = TimeFont1
    desc.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    desc.Text = (20+i) & "%"
    desc.TextSize = 12
    desc.TextColor = Colors.White
    p.AddView(desc, 55%x,20%y, 12%x,7%y) 'view #3
   
    Dim precio As Label
    precio.Initialize("")
    precio.Typeface = TimeFont1
    precio.Gravity = Gravity.LEFT
    precio.Text = (20+i*i*9) & "€"   
    precio.TextSize = 12
    precio.TextColor = Colors.Black
    p.AddView(precio, 67%x,21.5%y, 15%x,7%y) 'view #4
   
    Dim borde3 As ImageView
    borde3.Initialize("borde3")
borde3.SetBackgroundImage(LoadBitmap(File.DirAssets,("borde3.png")))
            borde3.Gravity=Gravity.FILL
            p.AddView(borde3, 65.5%x,23.2%y, 10%x,0.2%y) 'view #5
   
    Dim preciodescuento As Label
    preciodescuento.Initialize("")
    preciodescuento.Typeface = TimeFont1
    preciodescuento.Gravity = Gravity.LEFT
    preciodescuento.Text = ((20+i*i*9)/2) & "€"   
    preciodescuento.TextSize = 18
    preciodescuento.TextColor = Colors.Red
    p.AddView(preciodescuento, 77%x,20.5%y, 215%x,7%y) 'view #6
   
TimeFont = Typeface.LoadFromAssets("digi.ttf")

    reloj(ii-1).Initialize("")
        reloj(ii-1).Typeface = TimeFont
    reloj(ii-1).Gravity = Gravity.LEFT
    hora=DateTime.GetHour(DateTime.Now)
    minuto=DateTime.GetMinute(DateTime.Now)
    segundo=DateTime.GetSecond(DateTime.Now)
    reloj(ii-1).TextSize = 17
    reloj(ii-1).TextColor = Colors.Red
    reloj(ii-1).Text = hora&":"&minuto&":"&segundo   

    p.AddView(reloj(ii-1), 53%x,30%y, 20%x,6%y) 'view #7

If ii=10 Then
    tiempo3.Enabled=True
    End If
    Dim borde As ImageView
    borde.Initialize("borde")
borde.SetBackgroundImage(LoadBitmap(File.DirAssets,("borde.png")))
            borde.Gravity=Gravity.FILL
            p.AddView(borde, 1%x,37%y,94%x,0.2%y) 'view #8
   
    Dim borde2 As ImageView
    borde2.Initialize("borde2")
borde2.SetBackgroundImage(LoadBitmap(File.DirAssets,("borde2.png")))
            borde2.Gravity=Gravity.FILL
            p.AddView(borde2, 0%x,43%y,100%x,4%y) 'view #9
   
    b(ii-1).Initialize("b"&(ii-1)) 'all buttons click events will be handled with Sub Button_Click
    b(ii-1).Color=Colors.Red
    b(ii-1).TextColor=Colors.White
b(ii-1).Typeface = TimeFont1
    b(ii-1).Text="VER"
    b(ii-1).Gravity=Gravity.CENTER_HORIZONTAL
    b(ii-1).Enabled=True
    b(ii-1).Visible=True
    b(ii-1).Text =ii& " VER"
    b(ii-1).TextSize=12
    b(ii-1).Tag=(ii-1)
p.AddView(b(ii-1),  75%x,28%y, 20%x,7%y) 'view #10

    Dim txtprod As Label
    txtprod.Initialize("")
    txtprod.Typeface = TimeFont1
    txtprod.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    txtprod.Text = Text
    txtprod.TextSize = 16
    txtprod.TextColor = Colors.Black
    p.AddView(txtprod, 57%x,5%y, 25%x, 5%y) 'view #11
   
    '    Dim logo As ImageView


'    Dim nombreemp As Label


'    Dim sector As Label

    Return p

End Sub

Sub    b2_Click

Log("va bien")

End Sub
Sub    b3_Click

Log("va asdasdasdasd")

End Sub
Sub    b9_Click

Log("xxxxxxxxxxxxxxxxx")

End Sub
thank you
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
... if it works consistently, doesn't break anything else or melt your processor, then it's good!
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
the point is this
B4X:
b(ii-1).Initialize("b"&(ii-1))
create and initialize buttons with diferent "names" ,seems for now run fine.
Thank you for your interest.
 
Upvote 0
Top