Hi!,
This is regarding XCustomListView example
Few queries.
1)Is is perfectly acceptable to send an integer (or long) value for the 'Value' Object into the
Add method of the CustomListView and capture that value in a String variable ?
I explain my requirement with an Example:
1)Assume that a control is created of CustomListView by name CLV1
Assume that the records of a database are to be displayed in the CustomListView CLV1
2) There is a layout file 'lytCLVItem' containing 2 labels lblCLVItemKey and lblCLVItemDescription
3) In the calling subroutine after capturing the values from the database (via JRDC2), assume that
the records is stored in 'res' (of DBResult) .
4) Assume that row(0) references value for 'Item key' and row(1) references value for 'ITEM Description'
where 'Item key' and 'Item Description' are the fields of a table whose data was fetched via JRDC2
5) Now the Add method for CLV1 is invoked as :
strItemKey=NumberFormat(row(0),0,0)
strItemDescription=row(1)
'Where the above strItemKey and strItemDescription are string variables declared for temporarily storing the field values as we sift through each row of the result
6) The Add method is invoked as
CLV1.Add( CreateMyListItem(CLV1.AsView.Width,80dip, strItemKey,strItemDescription), strItemKey)
NOTE: the strItemKey is a string variable being passed for Value Object..
6) The CreateMyListItem is coded as
Sub CreateMyListItem(Width as int, Height as Int, parItemKey as string, parItemDescription as string) as Panel
Dim p as B4XView=xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,Width,Height)
p.LoadLayout("lytCLVItem")
lblClvItemKey.text=parItemKey
lblCLVItemDescription.text=parItemDescription
Return P
end Sub
7) Sub CLV1_ItemClick (Index As Int, Value As Object)
dim strSelectedValue as string
strSelectedValue=Value
End Sub
My doubt:
i) whether strSelectedValue=Value is a proper assignment ..
I mean, it works for me but I am not sure as to whether I can
'assign an Object type to a String variable'.
ii) Assuming I have around 5000 such items, is it acceptable to assign this table unique key for every such item
This currently solves my problem of identifying which item was clicked so that I can do further activities on the basis of the user-selection.
But I want to know if there is a better way
8) How to write the code such that when I click on the lblClvItemKey , I should be able to get the item that has been clicked ?
Thanks.
This is regarding XCustomListView example
[B4X] [XUI] xCustomListView - cross platform CustomListView
Update: As several other libraries depend on xCustomListView library, it is no longer recommended to use the code module. Use the library instead. There are several extension classes that add more features to xCLV. They are listed at the end of this post. Video tutorial: xCustomListView is...
www.b4x.com
Few queries.
1)Is is perfectly acceptable to send an integer (or long) value for the 'Value' Object into the
Add method of the CustomListView and capture that value in a String variable ?
I explain my requirement with an Example:
1)Assume that a control is created of CustomListView by name CLV1
Assume that the records of a database are to be displayed in the CustomListView CLV1
2) There is a layout file 'lytCLVItem' containing 2 labels lblCLVItemKey and lblCLVItemDescription
3) In the calling subroutine after capturing the values from the database (via JRDC2), assume that
the records is stored in 'res' (of DBResult) .
4) Assume that row(0) references value for 'Item key' and row(1) references value for 'ITEM Description'
where 'Item key' and 'Item Description' are the fields of a table whose data was fetched via JRDC2
5) Now the Add method for CLV1 is invoked as :
strItemKey=NumberFormat(row(0),0,0)
strItemDescription=row(1)
'Where the above strItemKey and strItemDescription are string variables declared for temporarily storing the field values as we sift through each row of the result
6) The Add method is invoked as
CLV1.Add( CreateMyListItem(CLV1.AsView.Width,80dip, strItemKey,strItemDescription), strItemKey)
NOTE: the strItemKey is a string variable being passed for Value Object..
6) The CreateMyListItem is coded as
Sub CreateMyListItem(Width as int, Height as Int, parItemKey as string, parItemDescription as string) as Panel
Dim p as B4XView=xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,Width,Height)
p.LoadLayout("lytCLVItem")
lblClvItemKey.text=parItemKey
lblCLVItemDescription.text=parItemDescription
Return P
end Sub
7) Sub CLV1_ItemClick (Index As Int, Value As Object)
dim strSelectedValue as string
strSelectedValue=Value
End Sub
My doubt:
i) whether strSelectedValue=Value is a proper assignment ..
I mean, it works for me but I am not sure as to whether I can
'assign an Object type to a String variable'.
ii) Assuming I have around 5000 such items, is it acceptable to assign this table unique key for every such item
This currently solves my problem of identifying which item was clicked so that I can do further activities on the basis of the user-selection.
But I want to know if there is a better way
8) How to write the code such that when I click on the lblClvItemKey , I should be able to get the item that has been clicked ?
Thanks.