Android Question [SOLVED] Help with manipulating (card) views in xCustomListView

rabbitBUSH

Well-Known Member
Licensed User
Good Day/ Evening All

I started a project based on the example provided by @Erel :


The attached zipped project files refer. (NOTE the project will try to write SQL files to SD and I have not worked the permissions bits into this yet - so you may want to tweek that.)

I built the project in the ZIP from a larger project just to attempt to get to grips with the particular thing I have been struggling with : manipulating View elements on each card (label colours, checkbox flips, etc).

The relevant code tab in the IDE is listStuff and the associated script [lines 143 / 144 and 211->214].

In my test project the xCustomListView is loaded with panels, in this case a set of 9, just as expected from the example provided by Erel.

In my test you will see a label in the top right of each panel. This is blue with X as text. What I want is for the user to click the "X" and then it should switch off its Visible property and turn on the Visible property of a label lying underneath which would also be blue but with a TICK as the text. (In the card2 layout I have placed the TICK offset from the X just to make it visible during testing.)

The X label is Enabled on start. The underlying TICK label is never Enabled.

What I can't seem to do, and searches of the fora have not shown any solutions, is to get the X "button" to turn off (invisible) and the TICK button to turn on visible).

My guess is that this is a referencing problem that I can't figure out, OR, its possible to capture the Click action but not to change anything else and what I want to do is not possible.

So, the two labels (add2listlblAction1 [and] add2listlblAction2], to me seem to need something in front of them referring to either and array or a container :

{{ie -> SOMETHING.add2listlblAction1.Visible = True}}​

The reason for this conclusion is that when, for instance the X is clicked on the first card, the X on the LAST card (9 in the test) turned off and the TICK turned on (although it seems without the TICK itself visible for some reason - that could be another question).

I found previously when toying with the example that, while, the colour of the Action labels in the example changed on a click action, and, the click was captured, I could not "pernanently' change the text colour. The same applied to other text or elements on a specific card.

You may note that the action would be CARD specific which means obviously that the change from X to TICK is per card with the response to the click contained in Sub add2listlblAction1_Click {}.
 

Attachments

  • added-by-designer-3.zip
    141.5 KB · Views: 208

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
There are several ways to solve this.

The method I would recommend is using the tag element on the controls themselves.

The key thing to know is that a every call to loadlayout effectively overwrites the variables/controls on the layout with the current ones.

The trick is to saving these within the loop.
so within CreateItem, you could do something like:
B4X:
    add2listlblAction1.tag =     add2listlblAction2
    add2listlblAction2.tag =     add2listlblAction1


now in the click events you can access the other element
B4X:
Sub add2listlblAction1_Click
   dim thislabel as label = sender ' Get the actual clicked label,add2listlblAction1 point to the lastinstance loaded by Load Layout
   dim otherlabel as label = thislabel.tag ' get the other label from the tag

'switch visibility
thislabel.visible =false 
otherlabel.visible = true

The tag accepts objects so it is possible to add multiple items using CreateMap

B4X:
add2listlblAction1.tag = createmap("label2":add2listlblAction2,"title":lblTitle)
so later you can, get at other controls

B4X:
Sub add2listlblAction1_Click
   dim thislabel as label = sender ' Get the actual clicked label, add2listlblAction1 point to the lastinstance loaded by Load Layout

   dim mp as map = thislabel.tag

   dim otherlabel as label = mp.get("label2") ' get the other label from the tag
   dim titlelabel as label = mp.get("title")
'switch visibility
thislabel.visible =false 
otherlabel.visible = true
labeltitle.text = "Clicked action 1"

Hope that helps.

Andrew
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
@Andrew (Digitwell) Thanks; that makes sense. I guess I could see the direction but the technique wasn't within past experience. Haven't learnt the power of TAGs yet.

every call to loadlayout effectively overwrites the variables/controls on the layout with the current ones
Mmmm, must remember that point it didn't occur to me

Thanks for taking the time to review the code and offer this solution.

I will apply your suggestions which I am sure will be a great help.

Unfortunately, our electricity utility company is probably about to switch us off in their load-shedding campaign against the consumer, so the attempt to apply the fix will most likely be later early in the new day or during daylight tomorrow ...

Much appreciated, thanks....
 
Upvote 0

rabbitBUSH

Well-Known Member
Licensed User
@Andrew (Digitwell) Brilliant, Thanks for that; works perfectly. Much appreciated help and the elegant solution. More perfect than that only comes with being outside tonight's load shedding regions - - - - well, 'til tomorrow 5am......

cheers
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…