How do i use label touch event with Reflection library?

Bongo

Member
Licensed User
Longtime User
Hi all,

I'm sort of getting in at the deep end (for me at least) a bit too quickly but I thought I'd ask for help on this before I continue with the beginner's guide.

I'm making a simple price calculator. Please see the attached image of how it will look more or less.

You can see three lines of numbers at the top half of the screen. The user will input values under pack size, unit size and price and the app will calculate the final figure in the right column. I'll call these figures the 'user inputs' for this post to make it easy to refer to them.

I want to use the keypad you can see in the image, rather than the android keyboard, so I have set the 'user inputs' as label views rather than edit text views. I thought it would be a very simple task to let the user touch one of the user inputs (i.e labels) and within b4a code be able to simply detect which label was touched. However, having read up on it, it would seem I was mistaken!

I understand using the reflection library makes it possible to detect when a user touches a label. I've searched for a simple tutorial on here as to how to do this but I can't find anything. I read the document (on the Wiki I think) relating to the reflection but it goes way over my head and uses jargon I do not understand yet.

So I was hoping somebody might tell me the basics if how I can detect which label is touched using Reflection.

I have given each label a different name and a different tag. I need to be able to refer to the labels individually in the code to change the colour of the one that has been touched and read its tag value etc.

Thanks for any help.
 

Attachments

  • layout.jpg
    layout.jpg
    37.4 KB · Views: 310

lagore

Active Member
Licensed User
Longtime User
The easiest way is to put your labels onto transparent panels, set the panels with the same "event" but with different tags, in the sub for the panel event have a 'select' to determine which panel/label you are responding to. You can even have a long_click event with the panels if you want.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
You can't really EDIT the labels.

to "keep it simple" I'd suggest using the input text views.
That way you can copy n paste n edit all or a single character
taking advantage of the built in functionality of Andoird.

i.e. so you could go ahead and use the Android Keyboard.
(or maybe thats what you want is prevent the Adnroid keyboard from popping up
so you can use your own simplified keyboard? If so, my suggestion is don't.
As the pop KB is there to save on real estate.)

Another way is to have a grid list of items for display purposes taking up the entire screen.
And use a popup type screen layout for input and edit text views for data entry.
That way you could have say a hundred items.
You'd be able to scroll thru them with the grid list view.
Double click on a grid list view item and edi it using the popup dialog.

As in the drilliant dialog libraries here (popup for edit input data entry):
http://www.b4x.com/forum/additional-libraries-classes-official-updates/6776-dialogs-library.html


hth
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
It depends on what exactly you want to do.
If it's just to know what Label was touched (selected) you can use the Label's Click event.
To memorize the last selected Label you can define a variable SelectedLabel as Label and in the the Click event routine you set SelectedLabel to the Label that raised the event.

The small test program shows the principle.
B4X:
Sub Globals
    Dim Label1, Label2, Label3, SelectedLabel As Label
    Dim colLabel As Int                     : colLabel = Colors.Red
    Dim colSelectedLabel As Int     : colSelectedLabel = Colors.RGB(0, 128, 0)
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    SelectedLabel.Initialize("Label")
    SelectedLabel = Label1
End Sub

Sub Label_Click
    SelectedLabel.Color = colLabel
    Dim SelectedLabel As Label
    SelectedLabel = Sender
    SelectedLabel.Color = colSelectedLabel
End Sub
Best regards.
 

Attachments

  • SelectedLabel.zip
    6.5 KB · Views: 210
Upvote 0
Top