In Android Button btn = (Button) findViewById(;

what is btn here? or any other keyword who is using below syntax Keyword x = new findViewById(;

1 answer

  • answered 2018-07-11 03:56 Psypher

    btn stores the data of type Button(Button extends View) for a view that is identified by an identifier in the xml that is passed in the onCreate method. In another words its a variable of type Button which points to the view of type Button.

    Eg: In a layout file:

        android:text="@string/button_send" />

    In the java code file:

    Button btn = (Button) findViewById(;

    Using the instance of the button you can perform actions on the button like invoking some code when the button is clicked.

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Do something when button click

    You would need to start going over some reading material. Better to start from here