Search This Blog

Friday, November 11, 2011

Android find control reference in activity; reference control from code

There is a simple method that allows us to find a control from the code-behind (android’s activity): findViewById();

Remember to use setContentView(someLayout) before calling the find function to allow the controls to build themselves.

Find a button and bind an acion to it:

final Button button = (Button) findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //some action

No comments:

Post a Comment

If you like this post, please leave a comment :)