I want to set the UI elements from the code for an English learning App. There are more than 100 topics for each section of the app so I just created three pages of fragment changing UI elements according to the string I receive from getStringExtra. as follows:
when (activity?.intent?.getStringExtra("clickedGrammarTopic")) {
"To Be - am/is/are" -> {
binding.firstPageToolbarText.text = getText(R.string.tobe_amisare_fp_toolbar_text)
binding.firstPageTextOne.text = getText(R.string.tobe_amisare_fp_1)
binding.firstPageTablePronoun.text = getText(R.string.tobe_amisare_table_pronoun)
binding.firstPageTableAuxillaryVerb.text = getText(R.string.tobe_amisare_table_auxillary_verb)
binding.firstPageTableVerb.text = getText(R.string.tobe_amisare_table_pronoun)
binding.firstPageTablePronounI.text = getText(R.string.tobe_amisare_table_pronoun_I)
binding.firstPageTableAuxAm.text = getText(R.string.tobe_amisare_table_aux_am)
binding.firstPageTableVerbOne.text = getText(R.string.tobe_amisare_table_verb_one)
binding.firstPageTableTranslation.text = getText(R.string.tobe_amisare_table_translation)
binding.firstPageTablePronounYou.text = getText(R.string.tobe_amisare_table_pronoun_you)
binding.firstPageTableAuxAre.text = getText(R.string.tobe_amisare_table_aux_are)
binding.firstPageTableVerbTwo.text = getText(R.string.tobe_amisare_table_verb_two)
binding.firstPageTableTranslationTwo.text = getText(R.string.tobe_amisare_table_translation)
binding.firstPageTablePronounHe.text = getText(R.string.tobe_amisare_table_pronoun_he)
binding.firstPageTableAuxIs.text = getText(R.string.tobe_amisare_table_aux_is)
....
}
The problem here is whenever I try to add a new topic, I need to write over 50 lines of code. Is there an easier way to deal with this? If not, would this method have any negative effect on the overall performance of the app? (tried designing each page on .xml files ended up in a mess)