In my activity_main.xml, I have 26 buttons (one for each letter of the alphabet). They are labeled btn_a, btn_b... btn_z.
These buttons will play a sound file on click (the pronunciation of their letter). Therefore, I want to grab a reference to their button to add the onClickListener.
This would be troublesome to do 26 times especially if I adapt this to handle other languages. So I want to do something like
Button alphaButton=new Button[26];
char[] alphabet=['a','b'... 'z'];
for(int i=0;i<26;i++){
alphaButton[i]=(button) findViewById(R.id.btn_+alphavet[i]);
alphaButton[i].setOnClickListener(listener);
}
I know this might work with JavaScript (given some tweaks) but I can't think of a way to programmatically grab id's in Android Studio (Java not Kotlin).