Android Basics – How to use findViewById method

If you want to reference any UI component, defined in the Layout XML file, then you need to use the findViewById method.

In your Activity class add the following code snippet

TextView helloText = (TextView) findViewById(;
if(helloText != null){
Log.v(TAG, “Lets check the value in hello id “+helloText.getText());

Once you get a reference you can perform operations on the element.


Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: