Global variables - accessing from View class
Having a bit of a problem. Unfortunately I'm at work (not home) so cannot show code.
Basically, I've got three class files - my main class, which at the moment is handling the touchscreen functionality - an act class, which is an extends View and is called by the main class (draws on the screen) - and a global class, which contains global variables, all the functions to set and retrieve them etc.
Now, I've got the global variables working okay after following some tutorials and forum answers. The file is declared in the manifest and, in the main class (which I think is an extends application) works fine (using all the getApplicationContext stuff).
However, I really need to get them to work in the act class (which is an extends View) but they're not. I gather this is obviously because this is an extends View which is something it doesn't seem I can do anythin开发者_Python百科g about.
Anyone got any ideas?
Thanks.
For replies (as I'm a newb so can't answer yet, and comments don't seem to want to work with IE6 - our IT dept sucks)
@David Olsson - thanks, will give that a go when I get in.
@Aioobe - heh, no, not really in much of a hurry. Should've posted last night. Normally it's the other way round, I'm at home, not work so can't show code...
And if you are at my home can you check on the dog?
You could always use a method where you put the reference for the global variables. IE in your View class:
private MyGlobalVariables myVariables;
public void setGlobalVariable(MyGlobalVariables variables) {
myVariables = variables;
}
and then in your activity class I guess you have a reference to your View, if you don't just create one and use
myView.setGlobalVariable(myVariables);
精彩评论