EDIT:
This is the method I use to initialize
variables after the layout of the activity
is loaded in the onCreate()
method
private void initializeVariables() {
randomButton = (Button) findViewById(R.id.randomButton);
gameButton = (Button) findViewById(R.id.gameButton);
i = 1;
listIndex = 0;
nameList = PlayersNames.nameList;
villagerBundle = new ArrayList<>();
characters = new ArrayList<Card>();
players = new ArrayList<Player>();
villagerOne = new Villager();
villagerTwo = new Villager();
villagerThree = new Villager();
villagerFour = new Villager();
villagerFive = new Villager();
villagerBundle.add(villagerOne);
villagerBundle.add(villagerTwo);
villagerBundle.add(villagerThree);
villagerBundle.add(villagerFour);
villagerBundle.add(villagerFive);
}
ORIGINAL QUESTION:
I have 2 activities in Android.
In one i create:
public static Villager villagerOne;
villagerOne = new Villager();
Then in the other one I should access to the villagerOne
's mAlive
variable:
villagerOne.getMAlive();
For reference, these is the Card
class:
public class Card {
//Names
public String mCharacter;
//Status
private boolean mAlive;
private boolean mDefended;
private boolean mOwled;
private boolean mLastSavaged;
private boolean mLastLynched;
//Constructor
public Card(){
}
public void setMCharacter(String value){
this.mCharacter = value;
}
public void setMAlive(boolean alive){
this.mAlive = alive;
}
public String getMCharacter(){
return mCharacter;
}
public boolean getMAlive(){
return mAlive;
}
}
And this is the Villager
class which extends Card
:
public class Villager extends Card {
public Villager(){
mCharacter = "Villager";
}
}