Android Question CLVNested- Adding a Record Using CustomListView1_ItemClick Event

Mahares

Expert
Licensed User
Longtime User
When I click an item in Customlistview1, a record of its own is added, but it is added to the end of list instead of showing up under the clicked item bottom of the list, which is what I like to see I like to see the record added for Brandon to be below the last record Shuckert of Stapelton Anthony.
Thank you.

Below is my code to add the record and a screenshot of the customlistview placement of the new record.
B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)   'Customlistview1 is the main xCLV
   ' CustomListView1.AddTextItem(Value, Value)  'This line is just to show which item was clicked
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 100%x, 200dip)
    p.LoadLayout("Item")     'Layout has clvItem customlistview
    Dim pp As B4XView = xui.CreatePanel("")
    pp.SetLayoutAnimated(0, 0, 0, clvItem.AsView.Width, clvItem.AsView.Height/4)
    pp.LoadLayout("fourlabels")    'Layout has 4 labels that hold the data
    lbl=Array As Label(l1, l2, l3, l4)
    lbl(0).Text="2023-02-13"
    lbl(1).Text="Brandon"
    lbl(2).Text="11:00-12:30"
    lbl(3).Text="99999"   
    clvItem.Add(pp, lbl(1).Text)
    CustomListView1.Add(p, Value)
End Sub

1676376739852.png
 

Attachments

  • 1676376145127.png
    1676376145127.png
    61.5 KB · Views: 33
Solution
1. Add all the nested CLV items to a list:
B4X:
CustomListView1.AddTextItem(currentDoctor, currentDoctor)
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 100%x, 200dip)
p.LoadLayout("Item")
clvItems.Add(clvItem)

2. The only place where you can use the global clvItem is right after the "Item" layout is loaded. This is the only case where it will reference the correct CLV.

B4X:
Sub CLVItem_ItemClick (Index As Int, Value As Object)
    Dim clvItem As CustomListView = Sender
    Log(Value)
    Log("clvitem: " & clvItem.Size)
End Sub

B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)   'Customlistview1 is the main xCLV
    Log("clv size: " & CustomListView1.Size)
    Dim pp As B4XView =...

Mahares

Expert
Licensed User
Longtime User
Best if you create a small project with the code. It should be easy to fix.
Here it is attached. It is for now a default project before I eventually convert to your preferred project type.
 

Attachments

  • xClvNestedForForum021423.zip
    15.2 KB · Views: 38
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Add all the nested CLV items to a list:
B4X:
CustomListView1.AddTextItem(currentDoctor, currentDoctor)
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 100%x, 200dip)
p.LoadLayout("Item")
clvItems.Add(clvItem)

2. The only place where you can use the global clvItem is right after the "Item" layout is loaded. This is the only case where it will reference the correct CLV.

B4X:
Sub CLVItem_ItemClick (Index As Int, Value As Object)
    Dim clvItem As CustomListView = Sender
    Log(Value)
    Log("clvitem: " & clvItem.Size)
End Sub

B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)   'Customlistview1 is the main xCLV
    Log("clv size: " & CustomListView1.Size)
    Dim pp As B4XView = xui.CreatePanel("")
    pp.SetLayoutAnimated(0, 0, 0, clvItem.AsView.Width, clvItem.AsView.Height/4)
    pp.LoadLayout("fourlabels")    'Layout has 4 labels that hold the data
    lbl=Array As Label(l1, l2, l3, l4)
    lbl(0).Text="2023-02-13"
    lbl(1).Text="Brandon"
    lbl(2).Text="11:00-12:30"
    lbl(3).Text="99999"
    clvItems.Get(Floor(Index / 2)).As(CustomListView).Add(pp, lbl(1).Text)
End Sub

Note that the index is divided by 2.
 
Upvote 0
Solution
Top