Hey all,
I've been trying to figure this out on my own but I'm new to Android and I can't find the answer.
I have an app with 10+ textviews and I want to create a simple loop to set the text of each one. Each textview is named sequentially "storyTitle1", "storyTitle2", "storyTitle3", etc. And the string I'm putting in each textview has already been set and can be called using getTitle(1), getTitle(2), getTitle(3), etc.
My question is, how can I setText using a variable object name?
for (int i = 10; i >= 1; i--) {
currentObject = "storyTitle" + i; // current object now equals "storyTitle1"
storyTitle1.setText(parsedDataSet.getTitle(i)); //works, but I want storyTitle1 to be the variable currentObject
}
Many thanks for your help.
I've been trying to figure this out on my own but I'm new to Android and I can't find the answer.
I have an app with 10+ textviews and I want to create a simple loop to set the text of each one. Each textview is named sequentially "storyTitle1", "storyTitle2", "storyTitle3", etc. And the string I'm putting in each textview has already been set and can be called using getTitle(1), getTitle(2), getTitle(3), etc.
My question is, how can I setText using a variable object name?
for (int i = 10; i >= 1; i--) {
currentObject = "storyTitle" + i; // current object now equals "storyTitle1"
storyTitle1.setText(parsedDataSet.getTitle(i)); //works, but I want storyTitle1 to be the variable currentObject
}
Many thanks for your help.
