I am making a hangman game, in the main Activity, there is a GridLayout containing the buttons for each letter. I would like to set a Button array in java to include all of the buttons and access them (in order to use them in java methods, as my teacher instructed us). My question is, what would be the easiest way to identify the buttons in Java, and how can I add them to said Button array? Thanks in advance. This is my first question here.
EDIT
The letters are not English letters and in this picture you can see the design of the GridLayout
.
Notice that the language direction is RTL instead of LTR which means I used a reverse order of the columns.
So, in addition to my first question, is there any way to 'reverse' the numbers' order from LTR to RTL?
You don't need an array to identify the buttons. Use an array to identify just the buttons that was pressed.
If your button contains the letter as a text...:
<Button
android:id="@+id/alef_button"
...
android:text="א" />
<Button
android:id="@+id/bet_button"
...
android:text="ב" />
Then you can use the same method as a listener for all buttons:
public void onButtonClick(View view) {
Button pressedButton = (Button) view;
if("א".equals(pressedButton.getText())) {
putOnArray("alef");
} else if("ב".equals(pressedButton.getText())) {
putOnArray("bet");
} ...
}