Android Question How create = member in CustomView (control)

Roberto P.

Well-Known Member
Licensed User
Longtime User
Good morning and happy holidays to all
in a customcontrol, how do I create a method that allows you to assign and read the value with "="?
For example:

dim MControl as CMyControl

MControl = "hello"

In CMYControl I control EditTex that I value, type:

'-----------------------------------
sub = (ADATA as String)
mText.Text = ADATA
end sub

I hope it is clear
thank you
 

DonManfred

Expert
Licensed User
Longtime User
I hope it is clear
no. i did NOT understand what exactly you want to do. You should describe it more clearly and you should provide a sample project which is describing the problem
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Magari in italiano sarebbe più chiaro ;).

I think that in many cases it is better to expose the constituent views directly, the TextView.
It is not so professional but so you do not have to "replicate" every property of the view.
Anyway, you need to create a Property.

A module variable for the property, for example mADATA, in the Globals routine and then:

B4X:
Public Sub setADATA(ADATA As String)
    mText.Text = ADATA
    mADATA = ADATA
End Sub
Public Sub getADATA As String
    Return mADATA
End Sub


or

B4X:
Public Sub GetADATAet As EditText
   Return mText
End Sub
 
Last edited:
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
va bene, scriviamo in Italiano, sperando di essere più chiaro.

In realtà è diverso da quello che scrivi tu, perchè vorrei implementare un metodo analogo alla logica degli overload degli operatori del C++, ovvero ridefinire l'operatore con lo scopo di assegnare o leggere un valore di una classe (oggetto). Quindi, il risultato è il seguente:

dim aCtrlText as MyControl
aCtrlText = "pippo"

nella sua implementazione
dim mText as EditText


sub =(aValue as String)
mText.Text = aValue
end sub

Questo ha il vantaggio di non dover chiamare un metodo per assegnare o leggere le proprietà principale di un oggetto senza usare metodi espliciti, tipo

aCtrlText.SetData(aData as string)

come ho già fatto



spero sia chiaro.
Grazie a tutti
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Uhm... sono sveglio da poco (!) ma anche in italiano non mi è chiaro (e io intendevo di scrivere in italiano ma nel forum italiano, qui si deve scrivere in inglese).

Um ... I'm awake for a short time (!), but also in Italian it is not clear to me (and I meant to write in Italian but in the Italian forum, here you have to write in English).

Rileggo con calma e cerco di capire ;)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Guarda comunque che SetData come l'hai scritto tu non è la stessa cosa che creare una proprietà, in B4a.

In b4a devi usare set con la lettera S minuscola.

In B4A a property begins with set and get with the first letter lowercase.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
I did not know there was a difference, or rather that it is a way to create the object properties. you know if there is a dedicated thread so I document?

thanks/grazie
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See this tutorial. Especially the part ent the end of the post about Properties!
The rules for properties:
- Only relevant for classes.
- One or two subs with the format get<prop> / set<prop>. Note that get / set must be lower case.
- A property can be read-only (only get), write-only (only set) or both.
- The two subs types (parameter in the set sub and return type in the get sub) must be the same.
- Within the class you should call the methods directly. The property will not appear.
- The property cannot have the same name as a global variable.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Yahoooo, at least on the last day of the year I was faster than Speedy DonManfred
Cause you mostly talk in italian and then i decided to not look into that thread so often... ;)
A good chance to you to be faster ;-) (THIS TIME! :D)

AAAAANNNND... btw... My first answer in this thread here was 10 minutes before yours :D
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
are also fine properties. Better read the manual (well done)
Thank you all and happy new year
 
Upvote 0
Top