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. Android Development Workshops

Hi, i'm a student of PEC University of Technology, Chandigarh. We are 
conducting a Technical fest VYOM in da last week of march. We would like to 
conduct some sort of beginner level android development workshops during the 
fest. If someone is interested or if someone can give some references, it 
would be great if you could get in touch. My number is 09501461363.
website of fest - www.vyom.net.in

-- 

2. Custom view in an App Widget

Hello!

Am I correct in assuming that I can't use a custom view (a specialisation of 
View) in an App Widget? This guide: 
http://developer.android.com/guide/topics/appwidgets/index.html seems to 
suggest that this is the case.

:.:: mattias

-- 

3. another Android 3.0 question

4. For getting Adhoc package in Android

5. Maintaining a free and paid version & maybe other version

6. "Finish" Activity from Dialog.. Not finishing

7. im building a new device