Android Question copy clv item to another clv??

ilan

Expert
Licensed User
Longtime User
hi

is it possible to copy customlistviewitems to another customlistview?

copy complete the same item from one list to another.

and someone know a very simple way to sort clv items? by the first view (its a numeric label)

thank you
 

ilan

Expert
Licensed User
Longtime User
1. Use clv.GetPanel(x) to get each item and add it to the second list.

i try like this but its not working

B4X:
'start filling clv12b
   
    clv12b.Clear
   
    For i = 0 To listsort.Size - 1
   
        For i2 = 0 To clv12.GetSize - 1
        pnl = clv12.GetPanel(i2)
        lbl = pnl.GetView(0)
        copylb1 = lbl.Text
        lbl = pnl.GetView(1)
        copylb2 = lbl.Text
        lbl = pnl.GetView(2)
        copylb3 = lbl.Text
        lbl = pnl.GetView(4)
        copylb4 = lbl.Text
        lbl = pnl.GetView(5)
        copylb5 = lbl.Text
       
'        Msgbox(copylb5,"")
'        Msgbox(listsort.Get(i),"")
       
            If listsort.Get(i) = copylb5 Then
          '  clv12b.Add(CreateListItem2(copylb5, clv12b.AsView.Width,  50dip), 50dip, copylb5)
            clv12b.Add(pnl.Getview(i2),50, pnl.Getview(i2))
            Exit   
            End If
       
        Next
   
    Next


2. You will need to write some code. You can declare a custom type with the sorting text as one field and the panel as a second field. Add all the items to a List, call List.SortType to sort the list and then add the items to the CLV.

i did something like what u said but i thought there would be a easier way

B4X:
Sub startconvert

clv12.Clear
For i = 1 To 31
selecteddate = i
selecteddatesub
If lb1.Text <> "--:--"  Then
clv12.Add(CreateListItem(selecteddate, clv12.AsView.Width,  50dip), 50dip ,selecteddate)
End If
Next
listsorter
End Sub
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
'    Height = 60dip
    Dim sd As StateListDrawable
    sd.Initialize
    Dim bd1, bd2 As BitmapDrawable
    bd1.Initialize(LoadBitmap(File.DirAssets , "1b1.png"))
    bd2.Initialize(LoadBitmap(File.DirAssets, "1b2.png"))
    sd.AddState(sd.State_Pressed, bd2)
    sd.AddCatchAllState(bd1)
   
    Dim p As Panel
    p.Initialize("panel")
    p.Color = Colors.White
'    p.Color = sd2
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
'    b.SetBackgroundImage(LoadBitmap(File.DirAssets,"event-icon3.png"))
    b.Background = sd
    '    Dim chk As CheckBox
    '    chk.Initialize("")
   
    If lb2.Text <> "--:--" Then
        Dim lbl As Label
        lbl.Initialize("")
        lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl.Text = lb3.Text '"350.0"
        lbl.TextSize = 16
        lbl.TextColor = Colors.Black
        lbl.Color = Colors.RGB(244,247,252)
   
        Dim lbl3 As Label
        lbl3.Initialize("")
        lbl3.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl3.Text = lb1.Text '"07:00"
        lbl3.TextSize = 16
        lbl3.TextColor = Colors.Black
       
        Dim lbl2 As Label
        lbl2.Initialize("")
        lbl2.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl2.Text = lb2.Text '"16:15"
        lbl2.TextSize = 16
        lbl2.TextColor = Colors.Black
       
    Else If lb2.Text = "--:--" Then
   
        Dim lbl As Label
        lbl.Initialize("")
        lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl.Text = lb3.Text '"350.0"
        lbl.TextSize = 16
        lbl.TextColor = Colors.Red
        lbl.Color = Colors.RGB(244,247,252)
   
        Dim lbl3 As Label
        lbl3.Initialize("")
        lbl3.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl3.Text = lb1.Text '"07:00"
        lbl3.TextSize = 16
        lbl3.TextColor = Colors.Red
       
        Dim lbl2 As Label
        lbl2.Initialize("")
        lbl2.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
        lbl2.Text = lb2.Text '"16:15"
        lbl2.TextSize = 16
        lbl2.TextColor = Colors.Red
'        lbl2.Color = Colors.Red
'        SetAlpha(lbl2,50)
    End If
   
   
    Dim lbl4 As Label
    lbl4.Initialize("")
    lbl4.Gravity = Bit.OR(Gravity.TOP, Gravity.CENTER_HORIZONTAL)
    lbl4.Text = lb13.Text '"ראשון"
    lbl4.TextSize = 10
    lbl4.TextColor = Colors.White
    lbl4.Typeface = Typeface.DEFAULT_BOLD
   
    Dim lbl5 As Label
    lbl5.Initialize("")
    lbl5.Gravity = Bit.OR(Gravity.BOTTOM, Gravity.CENTER_HORIZONTAL)
    lbl5.Text = b1.Text ' buttontxt
    lbl5.TextSize = 15
    lbl5.TextColor = Colors.Black
    lbl5.Typeface = Typeface.DEFAULT_BOLD
   
    'special days like hofesh, machala, hag
   
    Dim lbl6 As Label
    lbl6.Initialize("")
    lbl6.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl6.Text = lb5.Text
    lbl6.TextSize = 16
    lbl6.TextColor = Colors.Gray 
   
    If lb5.Text.Contains("חופש") OR lb5.Text.Contains("מחלה") OR lb5.Text.Contains("חג") Then
    lbl6.TextColor = Colors.Gray
    lbl2.TextColor = Colors.Transparent
    lbl3.TextColor = Colors.Transparent
    Else
    lbl6.TextColor = Colors.Transparent
    End If
   
    '************ start hidden labels
    Dim lbl7 As Label
    lbl7.Initialize("")
    lbl7.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl7.Text = lb4.Text
    lbl7.TextSize = 16
    lbl7.TextColor = Colors.Gray 
    Dim lbl8 As Label
    lbl8.Initialize("")
    lbl8.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl8.Text = lb6.Text
    lbl8.TextSize = 16
    lbl8.TextColor = Colors.Gray     
    Dim lbl9 As Label
    lbl9.Initialize("")
    lbl9.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl9.Text = lb7.Text
    lbl9.TextSize = 16
    lbl9.TextColor = Colors.Gray 
   
    Dim lbl10 As Label
    lbl10.Initialize("")
    lbl10.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl10.Text = lb8.Text
    lbl10.TextSize = 16
    lbl10.TextColor = Colors.Gray 
   
    Dim lbl11 As Label
    lbl11.Initialize("")
    lbl11.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl11.Text = lb9.Text
    lbl11.TextSize = 16
    lbl11.TextColor = Colors.Gray 
   
    Dim lbl12 As Label
    lbl12.Initialize("")
    lbl12.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl12.Text = lb10.Text
    lbl12.TextSize = 16
    lbl12.TextColor = Colors.Gray 
   
    Dim lbl13 As Label
    lbl13.Initialize("")
    lbl13.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl13.Text = lb11.Text
    lbl13.TextSize = 16
    lbl13.TextColor = Colors.Gray 
   
    Dim lbl14 As Label
    lbl14.Initialize("")
    lbl14.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl14.Text = lb12.Text
    lbl14.TextSize = 16
    lbl14.TextColor = Colors.Gray 
   
    Dim lbl15 As Label
    lbl15.Initialize("")
    lbl15.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl15.Text = lb14.Text
    lbl15.TextSize = 16
    lbl15.TextColor = Colors.Gray     
   
    Dim lbl16 As Label
    lbl16.Initialize("")
    lbl16.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl16.Text = pred.Text
    lbl16.TextSize = 16
    lbl16.TextColor = Colors.Gray     
   
    Dim lbl17 As Label
    lbl17.Initialize("")
    lbl17.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl17.Text =  bb1.Text
    lbl17.TextSize = 16
    lbl17.TextColor = Colors.Gray     
   
    Dim lbl18 As Label
    lbl18.Initialize("")
    lbl18.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl18.Text = lbclbb1.Text
    lbl18.TextSize = 16
    lbl18.TextColor = Colors.Gray     
       
   
    '************ end hidden labels
    p.AddView(lbl, 0, 0, 80dip, Height) 'view #0
    p.AddView(lbl2, 80dip, 2dip, 70dip, Height - 4dip) 'view #1
    p.AddView(lbl3, 150dip, 2dip, 70dip, Height - 4dip) 'view #2
    p.AddView(b, 235dip, 2dip, 56dip,  Height - 5dip) 'view #3
    p.AddView(lbl4, 235dip, 5dip, 56dip,  Height - 5dip) 'view #4
    p.AddView(lbl5, 235dip, 0, 56dip,  Height - 7dip) 'view #5
    p.AddView(lbl6, 80dip, 2dip, 140dip, Height - 4dip) 'view #6
    '--------------------------------------------------'
    'add hidden info
    p.AddView(lbl7, 1000dip, 2dip, 140dip, Height - 4dip) 'view #7
    p.AddView(lbl8, 1100dip, 2dip, 140dip, Height - 4dip) 'view #8
    p.AddView(lbl9, 1200dip, 2dip, 140dip, Height - 4dip) 'view #9
    p.AddView(lbl10, 1300dip, 2dip, 140dip, Height - 4dip) 'view #10
    p.AddView(lbl11, 1400dip, 2dip, 140dip, Height - 4dip) 'view #11
    p.AddView(lbl12, 1500dip, 2dip, 140dip, Height - 4dip) 'view #12
    p.AddView(lbl13, 1600dip, 2dip, 140dip, Height - 4dip) 'view #13
    p.AddView(lbl14, 1700dip, 2dip, 140dip, Height - 4dip) 'view #14
    p.AddView(lbl15, 1800dip, 2dip, 140dip, Height - 4dip) 'view #15
    p.AddView(lbl16, 1900dip, 2dip, 140dip, Height - 4dip) 'view #16
    p.AddView(lbl17, 2000dip, 2dip, 140dip, Height - 4dip) 'view #17
    p.AddView(lbl18, 2100dip, 2dip, 140dip, Height - 4dip) 'view #18
   
'  lb1 = p1l1 ***
'  lb2 = p1l2 ***
'  lb3 = p1l3 ***
'  lb4 = p1date ***
'  lb5 = p1shift ***
'  lb6 = p1in ***
'  lb7 = p1out ***
'  lb8 = p1break ***
'  lb9 = p1time ***
'  lb10 = p1bonus ***
'  lb11 = p1total ***
'  lb12 = p1hozaot ***
'  lb13 = lbd1 'day label ***
'  pp = p1
'  pred = p1red ***
'  b1 = p1b ***
'  bb1 = bbb1 ***
'  lbclbb1 = cllb1 ***
'  lb14 = lbtxt1  'day info  ***
           
'    p.AddView(chk, 240dip, 2dip, 50dip, Height - 4dip) 'view #10
    Return p
   
   
   
End Sub
Sub listsorter
    Dim lbl As Label
    Dim pnl As Panel
    Dim bigger As Boolean
   
    lbl.Initialize("lbl")
   
    Dim listsort As List
    listsort.Initialize()
    listsort.Clear
    For i = 0 To clv12.GetSize - 1
    pnl = clv12.GetPanel(i)
    lbl = pnl.GetView(5)
   
        If listsort.Size = 0 Then
        listsort.Add(lbl.Text)
        Else
       
            For i2 = 0 To listsort.Size - 1
                If lbl.Text < listsort.Get(i2) Then
                listsort.InsertAt(i2,lbl.Text)
                bigger = False
                Exit
                Else
                bigger = True
                End If
            Next
           
            If bigger = True Then
            listsort.Add(lbl.Text)
            End If
           
        End If
    Next
   
    For i3 = 0 To listsort.Size - 1
    ListView2.AddSingleLine(listsort.Get(i3))
    Next
   
    'start filling clv12b
   
    clv12b.Clear
   
    For i = 0 To listsort.Size - 1
   
        For i2 = 0 To clv12.GetSize - 1
        pnl = clv12.GetPanel(i2)
        lbl = pnl.GetView(0)
        copylb1 = lbl.Text
        lbl = pnl.GetView(1)
        copylb2 = lbl.Text
        lbl = pnl.GetView(2)
        copylb3 = lbl.Text
        lbl = pnl.GetView(4)
        copylb4 = lbl.Text
        lbl = pnl.GetView(5)
        copylb5 = lbl.Text
       
'        Msgbox(copylb5,"")
'        Msgbox(listsort.Get(i),"")
       
            If listsort.Get(i) = copylb5 Then
            clv12b.Add(CreateListItem2(copylb5, clv12b.AsView.Width,  50dip), 50dip, copylb5)
            Exit   
            End If
       
        Next
   
    Next
   
   
    clv12.Clear
   
    For i = 0 To clv12b.GetSize - 1
        pnl = clv12b.GetPanel(i)
        lbl = pnl.GetView(0)
        copylb1 = lbl.Text
        lbl = pnl.GetView(1)
        copylb2 = lbl.Text
        lbl = pnl.GetView(2)
        copylb3 = lbl.Text
        lbl = pnl.GetView(4)
        copylb4 = lbl.Text
        lbl = pnl.GetView(5)
        copylb5 = lbl.Text
        clv12.Add(CreateListItem3(copylb5, clv12.AsView.Width,  50dip), 50dip ,copylb5)
    Next
   
'    Msgbox("done","")
   
End Sub
Sub CreateListItem2(Text As String, Width As Int, Height As Int) As Panel
'    Height = 60dip
   
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    b.SetBackgroundImage(LoadBitmap(File.DirAssets,"event-icon3.png"))
   
'    Dim chk As CheckBox
'    chk.Initialize("")
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl.Text = copylb1
    lbl.TextSize = 16
    lbl.TextColor = Colors.Black
    lbl.Color = Colors.RGB(244,247,252)
   
   
    Dim lbl2 As Label
    lbl2.Initialize("")
    lbl2.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl2.Text = copylb2
    lbl2.TextSize = 16
    lbl2.TextColor = Colors.Black
   
    Dim lbl3 As Label
    lbl3.Initialize("")
    lbl3.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl3.Text = copylb3
    lbl3.TextSize = 16
    lbl3.TextColor = Colors.Black
   
    Dim lbl4 As Label
    lbl4.Initialize("")
    lbl4.Gravity = Bit.OR(Gravity.TOP, Gravity.CENTER_HORIZONTAL)
    lbl4.Text = copylb4
    lbl4.TextSize = 10
    lbl4.TextColor = Colors.White
    lbl4.Typeface = Typeface.DEFAULT_BOLD
   
    Dim lbl5 As Label
    lbl5.Initialize("")
    lbl5.Gravity = Bit.OR(Gravity.BOTTOM, Gravity.CENTER_HORIZONTAL)
    lbl5.Text = copylb5
    lbl5.TextSize = 15
    lbl5.TextColor = Colors.Black
    lbl5.Typeface = Typeface.DEFAULT_BOLD
    p.AddView(lbl, 0, 0, 80dip, Height) 'view #0
    p.AddView(lbl2, 80dip, 2dip, 70dip, Height - 4dip) 'view #1
    p.AddView(lbl3, 150dip, 2dip, 70dip, Height - 4dip) 'view #2
    p.AddView(b, 235dip, 2dip, 56dip,  Height - 5dip) 'view #3
    p.AddView(lbl4, 235dip, 5dip, 56dip,  Height - 5dip) 'view #4
    p.AddView(lbl5, 235dip, 0, 56dip,  Height - 7dip) 'view #5
   
'    p.AddView(chk, 240dip, 2dip, 50dip, Height - 4dip) 'view #2
    Return p
   
   
   
End Sub
Sub CreateListItem3(Text As String, Width As Int, Height As Int) As Panel
'    Height = 60dip
   
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    b.SetBackgroundImage(LoadBitmap(File.DirAssets,"event-icon3.png"))
   
'    Dim chk As CheckBox
'    chk.Initialize("")
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl.Text = copylb1
    lbl.TextSize = 16
    lbl.TextColor = Colors.Black
    lbl.Color = Colors.RGB(244,247,252)
   
   
    Dim lbl2 As Label
    lbl2.Initialize("")
    lbl2.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl2.Text = copylb2
    lbl2.TextSize = 16
    lbl2.TextColor = Colors.Black
   
    Dim lbl3 As Label
    lbl3.Initialize("")
    lbl3.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    lbl3.Text = copylb3
    lbl3.TextSize = 16
    lbl3.TextColor = Colors.Black
   
    Dim lbl4 As Label
    lbl4.Initialize("")
    lbl4.Gravity = Bit.OR(Gravity.TOP, Gravity.CENTER_HORIZONTAL)
    lbl4.Text = copylb4
    lbl4.TextSize = 10
    lbl4.TextColor = Colors.White
    lbl4.Typeface = Typeface.DEFAULT_BOLD
   
    Dim lbl5 As Label
    lbl5.Initialize("")
    lbl5.Gravity = Bit.OR(Gravity.BOTTOM, Gravity.CENTER_HORIZONTAL)
    lbl5.Text = copylb5
    lbl5.TextSize = 15
    lbl5.TextColor = Colors.Black
    lbl5.Typeface = Typeface.DEFAULT_BOLD
    p.AddView(lbl, 0, 0, 80dip, Height) 'view #0
    p.AddView(lbl2, 80dip, 2dip, 70dip, Height - 4dip) 'view #1
    p.AddView(lbl3, 150dip, 2dip, 70dip, Height - 4dip) 'view #2
    p.AddView(b, 235dip, 2dip, 56dip,  Height - 5dip) 'view #3
    p.AddView(lbl4, 235dip, 5dip, 56dip,  Height - 5dip) 'view #4
    p.AddView(lbl5, 235dip, 0, 56dip,  Height - 7dip) 'view #5
   
'    p.AddView(chk, 240dip, 2dip, 50dip, Height - 4dip) 'view #2
    Return p
   
   
   
End Sub

can i make a library of the code i did and use it in other apps?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
like this erel

B4X:
    clv12b.Clear

    For i = 0 To listsort.Size - 1

        For i2 = 0 To clv12.GetSize - 1
        pnl = clv12.GetPanel(i2)
    
    
            If listsort.Get(i) = copylb5 Then
          '  clv12b.Add(CreateListItem2(copylb5, clv12b.AsView.Width,  50dip), 50dip, copylb5)
            clv12b.Add(pnl.Getview(i2),50, pnl.Getview(i2))
            Exit
            End If
    
        Next

    Next
just add a complete item from one clv to another
 
Upvote 0
Top