• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to set 10 textviews at once?

devmob

Lurker
Dec 7, 2009
1
0
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. :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones