Change TextView text in code

by kaloer » Mon, 13 Apr 2009 22:16:04 GMT


Sponsored Links
 Hi,

I have made a layout in Xml, which includes a TextView. The TextView
should show some text that is found in a database. Therefore, i cannot
find the text by using the @string/something. How can i define the
text from my code, without creating the whole layout in code?

My TextView has the id  "currentRankLabel".

I think i shall do something like this:

View currentRankText = this.findViewById(R.id.currentRankLabel);
currentRankText.setText("some text");

Best Regards,
Kaloer
--~--~---------~--~----~------------~-------~--~----~



Change TextView text in code

by Arnaud Weber » Mon, 13 Apr 2009 22:22:38 GMT


 That's almost it. but you need to cast your View as a TextView :
TextView currentRankText =
(TextView)  this.findViewById(R.id.currentRankLabel);
currentRankText.setText("some text");

2009/4/13 kaloer <mkal...@gmail.com>


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Change TextView text in code

by Mark Murphy » Mon, 13 Apr 2009 22:22:46 GMT


 > I have made a layout in Xml, which includes a TextView. The TextView

That should work fine, so long as you call findViewById() sometime after
setContentView() or otherwise inflating your layout.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~



Change TextView text in code

by kaloer » Mon, 13 Apr 2009 22:34:43 GMT


 Thank you! It works now :-)

//Kaloer
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to modify contact detail screen?

Hi All,  Just like to share some thoughts and ask if anyone knows how
to modify the stock Contacts detail screen.

I'm not 100% convinced I will adopt this strategy yet but I need to
allow the user of my application to maintain contact information, with
extra fields specific to my app' so I figured my choices are either
to

A: create my own contacts database,
B: Create my own database that just contains extra fields with a link
id to a contact in the factory contacts system so they can use both
systems.
C: Solely utilise the default contact system but add extra fields to
an extra contacts table using the V2 API.

I thinking the best solution would be C,  as it's already a good
contact manager with plenty of features that I'd also need in my app
prewritten, call number, directions to address. As well as users dont
have to synch or re-enter contacts if they want to use their stock
contacts system

One thing of interest I've noticed is the FaceBook app that comes pre-
installed on the nexus one.  When I view a contacts details, there is
a Facebook section of information, so if possible, I could add my own
section for my app like the facebook app has done that could be a good
merge of systems.

However I've no idea how they do that and show the facebook panel..

Any thoughts on this greatly appreciated, love to hear how others have
faced similar dilemmas.

2. Invoking the default Alarm clock app as ways for Apps to receive a intent at scheduled time



I do not believe so.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Training: http://commonsware.com/training

3. Continous Audio recording in memory

4. Invoking the default Alarm clock app as ways for Apps to receive a intent at scheduled time

5. Saving a file from within a Live Wallpaper

6. Unescape XML

7. What's best way to resume activity and play audio file after spawned thread completes download?