Android Question How to create a Sub Label & Variable_Click

SternFaun

Member
Licensed User
Hello together,

first at all sorry for my bad english, it´s not my mother tongue.

I have the trial version of B4A and i think about buying it. I have average knowledge in VBA.
Let´s come to my question. I´m creating a app for notes.
The text of each note is written in an Textfile (in Internal). The Textfile is named like "Note" & Int
(Int is an ongoing number).

I used the ScrollView to display all titles of the notes. The titles are also named like "Notetitle" & Int.
Now i have to say the app:
If Notetitle4 is clicked, then show Note4. I do this with the following code:

Sub Notetitle4_click
Display Note4
end sub

How can i get the example-number 4 variable, like:

sub Notetitle & Variable_Click
display Note & variable
end sub
 

derez

Expert
Licensed User
Longtime User
You should use "Sender" : give each line view in the scrollview the same event name (like "note"), and a tag with the note number.
Create a sub with the name of the event , in it define a new view like the note line and assign the sender to it.
now you have the number in lbl.tag
B4X:
Sub note_click
dim lbl as label = sender
' display note & lbl.tag
End sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
while adding/filling the scrollview you can use the Tag property of the title to store the note-ID
B4X:
title.caption = "Note &i
title.Tag = i

give all title the same eventname

B4X:
Sub Notetitle_click
  dim lbl as Label = sender
  DisplayNote("Note"&lbl.Tag)
end sub
 
Upvote 0

SternFaun

Member
Licensed User
Good evening both of you. Thanks for your answers. I will try this when i have time for it. I will give feedback. Thanks again, great community. Greetings from germany.
 
Upvote 0

SternFaun

Member
Licensed User
Hey together,

worked great, thanks for your help.

I have another question:
I added Checkboxes in the Scrollview next to the Notetitles. I want to check the notes which are supposed to be deleted. Each checkbox has the same tag as the notetitle which should be deleted. The idea is this:

Checkbox_CheckedChange
Checkbox = Sender
'Delete "Note"&Checkbox.tag'
End Sub

Problem is that the "Checkbox = Sender" function doesn´t work. It says always the last number, doesnt matter which checkbox i check.
For example I select the checkbox which has the tag 3 in a list of 6 checkboxes, then it says the sender has the tag 6 instead of 3. Why that?

Thanks for your answers.
 
Upvote 0
Top