Android Question Updating item in xCustomlistview

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

We have a list of sensor items (text and Gauge) in a xCustomListview. From a MQTT event we want to update the Gauge in certain items.

What is the best way to access xCustomlistview items directly and update a value in such an item?
 

udg

Expert
Licensed User
Longtime User
A few alternatives:
- (quick and dirty) since you know that panel x in your CLV corresponds to a specific gauge, in the MQTT message specify the x values too
- use panel tag on each gauge to identify it and parse the CLV when a MQTT message arrives (sporting that specific ID)
- mantain a list (or similar collection) which registers gauge IDs and their position in the CLV
These are just the first three that came to my mind.
 
Last edited:
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Ok, not sure how to do it on the B4A site. Setting a tag is possible but how can I retrieve the item and set it? Sample code? I guess using panel tag is the best way. I might need to change more items inside the panel and list.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
As suggested above .. knowing the panel index and position / order of the views within the panel you can then reference / edit the views.

From xCustomListView example .. there are 3 views on each panel / row (Label, Button, Checkbox)

B4X:
Dim pnl As B4XView = clv2.GetPanel(index)
Dim lbl As B4XView = pnl.GetView(0)    '1st view
Dim chk As B4XView = pnl.GetView(2)  '3rd view
lbl.Text = "Clicked!"  
' ...................
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I don't want to use an index but a key. Is that the tag option? I want to use custom identifiers which are set in the Tag of the panel. Would that work?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Absolutely. Your key is what I called Gauge ID.
If you have a few gauges, option 2 is ok. If they are a lot or if you update very frequently the gauges' data, consider option 3; it's just a trick to reach quickly the desidered item.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
So udg, how does it work with a tag? I see a sample with index but that's different. And can a tag contain characters? I want to use id's with characters in it.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
A tag is an object, so it can be everything you need. In your case it will probabily be a string representing the Gauge ID.
When an MQTT message arrives, containing a valid ID, you loop on the CLV items to find the one having that string as its Tag.
That's why I suggested the "trick". Looping can take time. Even a short 10 gauges list, if you have to update gauge #9 it implies that you traverse the CLV from start to that position in order to find the corresponding ID.
Using a map, a list or any other collection (even an array of longs) to maintain the position of any specific ID in respect to the CLV item index, let you discover very quickly the item you hace to update. You construct the list in parallel with adding panels to the CLV.
This begins to be useful if you have a lot of gauges or if you have to update them very frequently.
 
Upvote 0
Top