Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old December 7th, 2009, 07:22 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2009
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default How to set 10 textviews at once?

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.

devmob is offline  
Reply With Quote
Sponsors
Old December 7th, 2009, 09:27 PM   #2 (permalink)
Junior Member
 
Join Date: Oct 2009
Location: Pennsylvania, USA
Posts: 46
 
Device(s): Motorola Droid
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

You should be able to get the TextViews by id, passing them a string. If you assign them a series of incremental ids, you can loop and get them, or you can actually get all of the views that have IDs that match a certain pattern as an array using getById and getAllById, I believe. Unfortunately I am not at my dev computer at the moment.
wige is offline  
Reply With Quote
Old December 8th, 2009, 10:40 AM   #3 (permalink)
Junior Member
 
Join Date: Oct 2009
Location: Pennsylvania, USA
Posts: 46
 
Device(s): Motorola Droid
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

Ok, now that I am at my dev computer, I can say that the function is findViewById, where you can specify a string and be returned the appropriate view.
wige is offline  
Reply With Quote
Reply
Tags
loop, settext, variable object names


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:38 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.