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. Clone Device to sdcard.img

Is there a method  (using Mac OS X) would be great
That I can connect my Android Device   (non-rooted)
and clone it to become my sdcard.img   so I can use it for the emulator
and thus continue developing on the emulator  Yet  using all the apps and 
software features
of the device?

If possible could someone please be willing to post the steps and / or web link


Thanks in advance

-- 

2. android eclair bsp building on arm board

Hi,

I am building android eclair 2.1 for my smdk6410 board.
Kernel image "zImage" == 2.6.29
uboot 1.3.4

When i run the image(ramdisk-uboot.img, system.img) i get this error
message
"init: Unable to open persistent property directory /data/property
errno: 2"

and the screen is stuck at welcome screen with android written on it
and nothing else happens.

can anyone please help what is the problem.

Thanks and regards
Manoj

-- 

3. GPRS and RIL

4. Version Control for an Android branch

5. Injecting Data into Android's Location Manager

6. Adding an button to a custom view

7. Google IO 2011