Android Question Use Key Name as the Variable Name

Andy Whitehouse

Member
Licensed User
Longtime User
Hi,

Apologies if the answer to this question is elsewhere in the forum / documentation but I have looked extensively and can't see it has been raised before. Apologies also if there is a straightforward answer.

My question is, in a Map or KeyValueStore, is it possible to use the same name for the Key and a Variable, but, more importantly, automatically pass the resultant key value to the variable of the same name as the key?

e.g. My programme has a variable called 'TextColour1'. its value is 'Colors.Blue'.
I am using the Preference Manager Library to keep track / control of the keys and values.

If I save the value Colors.Blue to the Key "TextColour1", is there a way to automatically assign the returned value for the Key "TextColour1" to the variable 'TextColour1'.

I know I could rewrite my program to get values directly from the map, but in most instances I would prefer to work with values assigned to variables.

Many thanks,
Andy
 

Cableguy

Expert
Licensed User
Longtime User
A variable and a view (control) connot share the same name. in fact, no dubs are allowed in declared objects, views or variables. The best approach is to give as similar and logic names as possible, like in your example, "TextColour1" and "TxtColour1".
a Variable is automatically declared the moment you assign a value to it if not declared beforehand.
ex.
dim PText as String
or
PText = "MyPass"

both declare PText as String, the difference being that the Dim word declares an empty variable
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…