I instantiate the class with the Button extension and access the integer variable directly for better performance. I use constants to easily define the current setting variable.
I have constants declared by both the Button class and the Activity class that creates them. I found similar questions and I don’t think it’s good practice to create a class to just hold constants.
What is the best way to use the same constant declaration in both classes?
I am a beginner programmer, so it is possible that I missed a simple solution.
Button Class:
public class GridButton extends Button {
public int displayStatus;
private static final int UNTOUCHED = 1;
private static final int UNCOVERED = 2;
private static final int FLAGGED = 3;
private static final int HIT = 4;
...
}
Action class:
public class PlayGameActivity extends Activity {
private GridButton[][] gridButtons;
private static final int UNTOUCHED = 1;
private static final int UNCOVERED = 2;
private static final int FLAGGED = 3;
private static final int HIT = 4;
...
if (gridButtons[currentRow][currentColumn].displayStatus == FLAGGED)
{
}
}
source
share