Counter with 2 Buttons (plus/minus as Label) and 1 label (Counter as Label)

Bernd68

Member
Licensed User
Longtime User
Hi all,

i am looking for a solution to access the parent of a Label to get the lblCounter.Text Value to change that label (lblCounter.Text).

Following the examples from the Forum i use the following code to retrieve which Label (plus or minus) was clicked.

B4X:
Sub minus_click
   Dim sid As Int
   Dim btnMinus As Label
    btnMinus = Sender
    sid = btnMinus.Tag
   ToastMessageShow("Minus Nr clicked "&sid,False)
End Sub

The Button belongs to the same parent(=panel) as the lblCounter.

I thought a solution like this could work, but it does not:

B4X:
Sub minus_click

       Dim btnMinus As Label
       Dim parent as Parent '<-- Any Idea how to access the parent (a Panel) of btnMinus??
       parent = btnMinus.parentView '<-----Parent is a Panel that holds all labels
       t = parent.GetView(2) ' <--- lblCounter   
       counter = t.Text  
       t.Text = counter - 1  '<---

End Sub


I hope my question is clear ?

1 parent = panel holds 3 labels (1 should be minus, 1 should be plus, 1 is the counter)

Click on the Minus/Plus Label should change the counter.

Thanks for sharing any idea and/or example how to achieve this
Cheers Bernd
 

klaus

Expert
Licensed User
Longtime User
Here you are.
You were looking much too complicated.
What example in the forum did you get the code from ?
It can be done in different ways, in the example program you'll find two solutions.

Best regards.
 

Attachments

  • PlusMinus.zip
    6.5 KB · Views: 338
Upvote 0

Bernd68

Member
Licensed User
Longtime User
Hi Klaus,

thank you for the example.
I understand teh example,

but have the problem to implement it in your scrollViewExample found here:
http://www.b4x.com/forum/basic4andr...youts-getting-current-selected.html#post47763

So following the nice blue/red lined it is esay to get i.e. Label.Text and set the activity.title. But how would i achieve, to click the button on the right side of the example and update the Label on the left side.
Both views are childs of the same panel as their parent.
Each "row" panel is a child of the scrollview.panel.

So with calling the panel_click i can get the childs with getView(i), but how would i get the parent panel (row) to update the other child on the panel?

And i wan't to have a counter on each panel (=row) :)

I hope this is clearer

Thanks again
Bernd
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Is the attached program what you are looking for ?

Best regards.
 

Attachments

  • ScrollViewNPlusMinus.zip
    6.7 KB · Views: 248
  • ScrollViewNPlusMinus.jpg
    ScrollViewNPlusMinus.jpg
    66.1 KB · Views: 421
Upvote 0

Bernd68

Member
Licensed User
Longtime User
Hi Klaus,

thank you very much for your example :sign0098:

This is exactly what i want to do. I will no "dive into" your code and hope to get ride of my headache and find the right "translation" for my code

Cheers Bernd
 
Upvote 0
Top