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. Show dialog on exit

Hello,

I'm trying to show an alert dialog when the user exists my application
but it seems that although
i successfully build the Dialog nothing happens and the app. simply
closes.
Is there a way to implement it?
Thanks.

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

2. Is it possible to have, horizontal "listview", scrolling horizontally?

Yes there is, it's called a Gallery.






-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

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

3. Child TextView in ScrollView with large amount of text pushes other views off the screen

4. Apps built with 1.5 get a black-backgound icon in the Market

5. Android 1.5 - crash during drawing of multiline TextView

6. Intellectual Property Office approves software patent for UK

7. Testing on Devices and Networks