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(R.id.helloId);
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.

Code: https://github.com/ankur-srivastava/HelloAndroid/blob/master/app/src/main/java/com/edocent/helloandroid/MainActivity.java

Author: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s