I have been trying to find a way to set variables for one class while in another class withous changing intents. Maybe I’m searching the wrong things, maybe I’m over complicating this, I don’t know.
Basically, what I am doing at the moment is getting the listView item that is selected, checking its index value, and chaning a variable or two(from a different class) based on the choice.
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
theGame settings = null;
switch(position){
case 0:
settings.baseWave = 10;
settings.baseRate = 5;
break;
case 1:
settings.baseWave = 20;
settings.baseRate = 10;
break;
case 2:
settings.baseWave = 30;
settings.baseRate = 15;
break;
}
}
“theGame” is my outside class and “baseWave” and “baseRate” are the corrisponding varriables. Obviously, what I am doing here is not working for me. Im fairly new at all of this so be gentle.
Thank you for any help you can offer, it is much appreciated 🙂
~TG
It’s nice that it struck you that you may have a bad design, but it should also have struck you that you don’t know Java, that you’re having this problem because you don’t know Java, and that a good Java book would help you.
Well, this is the shortest path to getting this attempt of yours working: have theGame store a reference to itself in a static member; use the static member in your code.
That is,
And elsewhere:
TheGame.theGame.baseWave = 10 * (position + 1);Or you may need it put this way:
A good Java book would describe this sort of thing to you, give you a name for it, and warn you away from it.