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